| 1 | import x.executor |
| 2 | |
| 3 | struct TextureUpload { |
| 4 | id int |
| 5 | bytes int |
| 6 | } |
| 7 | |
| 8 | fn main() { |
| 9 | mut render := executor.new(queue_size: 8)! |
| 10 | uploaded := chan TextureUpload{cap: 3} |
| 11 | producer_done := chan bool{cap: 1} |
| 12 | |
| 13 | producer := spawn fn [mut render, producer_done, uploaded] () { |
| 14 | for id in 0 .. 3 { |
| 15 | bytes := 128 + id |
| 16 | render.try_post(fn [uploaded, id, bytes] () ! { |
| 17 | uploaded <- TextureUpload{ |
| 18 | id: id |
| 19 | bytes: bytes |
| 20 | } |
| 21 | }) or { |
| 22 | producer_done <- false |
| 23 | return |
| 24 | } |
| 25 | } |
| 26 | producer_done <- true |
| 27 | }() |
| 28 | |
| 29 | producer_ok := <-producer_done |
| 30 | if !producer_ok { |
| 31 | eprintln('producer could not submit render uploads') |
| 32 | exit(1) |
| 33 | } |
| 34 | drained := render.drain_pending(8)! |
| 35 | if drained != 3 { |
| 36 | eprintln('expected 3 render uploads, got ${drained}') |
| 37 | exit(1) |
| 38 | } |
| 39 | |
| 40 | mut total_bytes := 0 |
| 41 | for _ in 0 .. 3 { |
| 42 | total_bytes += (<-uploaded).bytes |
| 43 | } |
| 44 | println('uploaded ${drained} synthetic textures, bytes=${total_bytes}') |
| 45 | |
| 46 | render.stop() |
| 47 | if render.drain_pending(1)! != 0 { |
| 48 | eprintln('unexpected render job after stop') |
| 49 | exit(1) |
| 50 | } |
| 51 | render.wait()! |
| 52 | producer.wait() |
| 53 | } |
| 54 | |