Skip to content

Commit 05b7a62

Browse files
committed
[examples/counter.jai] demonstrate coroutines at compile time
1 parent 47e4e95 commit 05b7a62

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

examples/counter.jai

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,26 @@ main :: () {
4242
output_path = "../build/",
4343
output_executable_name = "counter_jai",
4444
});
45+
46+
coroutine_init();
47+
defer coroutine_finish();
48+
coroutine_go((arg: *void) #c_call {
49+
push_context {
50+
for 0..5 {
51+
print("[%] You can actually use\n", coroutine_id());
52+
coroutine_yield();
53+
}
54+
}
55+
});
56+
coroutine_go((arg: *void) #c_call {
57+
push_context {
58+
for 0..5 {
59+
print("[%] coroutines at compile-time\n", coroutine_id());
60+
coroutine_yield();
61+
}
62+
}
63+
});
64+
while coroutine_alive() > 1 {
65+
coroutine_yield();
66+
}
4567
}

0 commit comments

Comments
 (0)