| 1 | import context |
| 2 | import time |
| 3 | import x.async as xasync |
| 4 | |
| 5 | fn main() { |
| 6 | xasync.with_timeout(20 * time.millisecond, fn (mut ctx context.Context) ! { |
| 7 | done := ctx.done() |
| 8 | select { |
| 9 | _ := <-done { |
| 10 | return ctx.err() |
| 11 | } |
| 12 | 1 * time.second { |
| 13 | return error('work unexpectedly finished') |
| 14 | } |
| 15 | } |
| 16 | }) or { |
| 17 | println('timeout result: ${err.msg()}') |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | eprintln('expected timeout error') |
| 22 | exit(1) |
| 23 | } |
| 24 |