1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: add a simple coroutine example

This commit is contained in:
Alexander Medvednikov
2023-05-29 01:35:34 +02:00
parent 1be539d20f
commit 3f62487409
3 changed files with 64 additions and 3 deletions

View File

@ -0,0 +1,37 @@
// Build with
// v -use-coroutines simple_coroutines.v
//
import coroutines
import time
fn foo(a int) {
for {
println('hello from foo() a=${a}')
coroutines.sleep(1 * time.second)
}
}
fn foo2(a int) {
for {
println('hello from foo2() a=${a}')
coroutines.sleep(2 * time.second)
}
}
fn foo3(a int) {
for {
println('hello from foo3() a=${a}')
coroutines.sleep(3 * time.second)
}
}
fn main() {
go foo(10)
go foo2(20)
go foo3(30)
for {
println('hello from MAIN')
coroutines.sleep(1 * time.second)
}
println('done')
}