| 1 | import time |
| 2 | import x.executor |
| 3 | |
| 4 | fn main() { |
| 5 | mut ex := executor.new(queue_size: 1)! |
| 6 | ran := chan string{cap: 2} |
| 7 | |
| 8 | ex.try_post(fn [ran] () ! { |
| 9 | ran <- 'first' |
| 10 | })! |
| 11 | |
| 12 | ex.try_post(fn () ! {}) or { println('try_post backpressure: ${err.msg()}') } |
| 13 | |
| 14 | ex.post_with_timeout(20 * time.millisecond, fn () ! {}) or { |
| 15 | println('timeout bounded admission: ${err.msg()}') |
| 16 | } |
| 17 | |
| 18 | if !ex.run_one()! { |
| 19 | eprintln('queued job did not run') |
| 20 | exit(1) |
| 21 | } |
| 22 | println(<-ran) |
| 23 | |
| 24 | ex.stop() |
| 25 | if ex.run_one()! { |
| 26 | eprintln('unexpected job after stop') |
| 27 | exit(1) |
| 28 | } |
| 29 | ex.wait()! |
| 30 | } |
| 31 | |