Set sets the Future (value, error) pair. All currently blocked and future Get calls will return it.
(val interface{}, err error)
| 46 | // Set sets the Future (value, error) pair. All currently blocked and future |
| 47 | // Get calls will return it. |
| 48 | func (f *Future) Set(val interface{}, err error) { |
| 49 | if f == nil { |
| 50 | panic("nil future used") |
| 51 | } |
| 52 | |
| 53 | f.mu.Lock() |
| 54 | defer f.mu.Unlock() |
| 55 | |
| 56 | if f.set { |
| 57 | stack := debug.Stack() |
| 58 | log.Println("Future.Set called multiple times", stack) |
| 59 | log.Println("value=", val, "err=", err) |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | f.set = true |
| 64 | f.val = val |
| 65 | f.err = err |
| 66 | |
| 67 | close(f.notify) |
| 68 | } |
| 69 | |
| 70 | func (f *Future) Get() (interface{}, error) { |
| 71 | if f == nil { |