(ctx context.Context)
| 50 | } |
| 51 | |
| 52 | func SlowFunction(ctx context.Context) Future { |
| 53 | resCh := make(chan string) |
| 54 | errCh := make(chan error) |
| 55 | |
| 56 | go func() { |
| 57 | select { |
| 58 | case <-time.After(time.Second * 2): |
| 59 | resCh <- "I slept for 2 seconds" |
| 60 | errCh <- nil |
| 61 | case <-ctx.Done(): |
| 62 | resCh <- "" |
| 63 | errCh <- ctx.Err() |
| 64 | } |
| 65 | }() |
| 66 | |
| 67 | return &InnerFuture{resCh: resCh, errCh: errCh} |
| 68 | } |