()
| 10 | ) |
| 11 | |
| 12 | func ExampleStream() { |
| 13 | times := []int{20, 52, 16, 45, 4, 80} |
| 14 | |
| 15 | stream := New() |
| 16 | for _, millis := range times { |
| 17 | dur := time.Duration(millis) * time.Millisecond |
| 18 | stream.Go(func() Callback { |
| 19 | time.Sleep(dur) |
| 20 | // This will print in the order the tasks were submitted |
| 21 | return func() { fmt.Println(dur) } |
| 22 | }) |
| 23 | } |
| 24 | stream.Wait() |
| 25 | |
| 26 | // Output: |
| 27 | // 20ms |
| 28 | // 52ms |
| 29 | // 16ms |
| 30 | // 45ms |
| 31 | // 4ms |
| 32 | // 80ms |
| 33 | } |
| 34 | |
| 35 | func TestStream(t *testing.T) { |
| 36 | t.Parallel() |