Method
GetContext
(ctx context.Context)
Source from the content-addressed store, hash-verified
| 76 | } |
| 77 | |
| 78 | func (f *Future) GetContext(ctx context.Context) (interface{}, error) { |
| 79 | if f == nil { |
| 80 | panic("nil future used") |
| 81 | } |
| 82 | |
| 83 | f.mu.RLock() |
| 84 | if f.set { |
| 85 | val := f.val |
| 86 | err := f.err |
| 87 | f.mu.RUnlock() |
| 88 | return val, err |
| 89 | } |
| 90 | |
| 91 | f.mu.RUnlock() |
| 92 | select { |
| 93 | case <-f.notify: |
| 94 | case <-ctx.Done(): |
| 95 | return nil, ctx.Err() |
| 96 | } |
| 97 | |
| 98 | f.mu.RLock() |
| 99 | defer f.mu.RUnlock() |
| 100 | if !f.set { |
| 101 | panic("future: Notification received, but value is not set") |
| 102 | } |
| 103 | |
| 104 | return f.val, f.err |
| 105 | } |