v4 / vlib / x / executor / examples / basic_post.v
24 lines · 20 sloc · 393 bytes · e80386b6af8a071a2e13fd654ebcdb2105fb9202
Raw
1import x.executor
2
3fn main() {
4 mut ex := executor.new(queue_size: 4)!
5 updates := chan string{cap: 1}
6
7 ex.try_post(fn [updates] () ! {
8 updates <- 'owner state updated'
9 })!
10
11 ran := ex.run_one()!
12 if !ran {
13 eprintln('executor did not run the queued job')
14 exit(1)
15 }
16
17 println(<-updates)
18 ex.stop()
19 if ex.run_one()! {
20 eprintln('unexpected job after stop')
21 exit(1)
22 }
23 ex.wait()!
24}
25