1
0
dust/dust_examples/async_count.ds

24 lines
421 B
Plaintext
Raw Normal View History

2024-06-28 19:35:18 +00:00
count_slowly = fn (
multiplier: int,
sleep: fn (milliseconds: int),
write_line: fn (output: str),
) {
2024-06-24 19:07:11 +00:00
i = 0
while i < 10 {
sleep_time = i * multiplier;
2024-06-28 19:35:18 +00:00
sleep(sleep_time)
write_line(i as str)
2024-06-24 19:07:11 +00:00
i += 1
}
}
async {
2024-06-28 19:35:18 +00:00
count_slowly(50, thread.sleep, io.write_line)
count_slowly(100, thread.sleep, io.write_line)
count_slowly(200, thread.sleep, io.write_line)
count_slowly(250, thread.sleep, io.write_line)
2024-06-24 19:07:11 +00:00
}