1
0
dust/dust_examples/async_count.ds

24 lines
421 B
Plaintext

count_slowly = fn (
multiplier: int,
sleep: fn (milliseconds: int),
write_line: fn (output: str),
) {
i = 0
while i < 10 {
sleep_time = i * multiplier;
sleep(sleep_time)
write_line(i as str)
i += 1
}
}
async {
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)
}