| 1 | import context |
| 2 | import time |
| 3 | import x.async as xasync |
| 4 | |
| 5 | fn main() { |
| 6 | mut group := xasync.new_group(context.background()) |
| 7 | |
| 8 | group.go(fn (mut ctx context.Context) ! { |
| 9 | _ = ctx |
| 10 | time.sleep(20 * time.millisecond) |
| 11 | return error('stop group') |
| 12 | })! |
| 13 | |
| 14 | group.go(fn (mut ctx context.Context) ! { |
| 15 | done := ctx.done() |
| 16 | select { |
| 17 | _ := <-done { |
| 18 | return ctx.err() |
| 19 | } |
| 20 | 1 * time.second { |
| 21 | return error('worker did not observe cancellation') |
| 22 | } |
| 23 | } |
| 24 | })! |
| 25 | |
| 26 | group.wait() or { |
| 27 | println('group failed: ${err.msg()}') |
| 28 | return |
| 29 | } |
| 30 | } |
| 31 | |