mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
coroutines: $if is_coroutine? {
This commit is contained in:
parent
4e21b2ab4e
commit
6fe6fe887d
@ -3,6 +3,8 @@
|
||||
//
|
||||
import coroutines
|
||||
import time
|
||||
import os
|
||||
import net.http
|
||||
|
||||
fn foo(a int) {
|
||||
for {
|
||||
@ -12,9 +14,17 @@ fn foo(a int) {
|
||||
}
|
||||
|
||||
fn foo2(a int) {
|
||||
mut i := 0
|
||||
for {
|
||||
println('hello from foo2() a=${a}')
|
||||
coroutines.sleep(2 * time.second)
|
||||
i++
|
||||
// resp := http.get('https://vlang.io/utc_now') or { panic(err) }
|
||||
// resp := http.get('http://example.com') or { panic(err) }
|
||||
// println(resp)
|
||||
// mut f := os.create('/tmp/FOO2_a${i}') or { panic(err) }
|
||||
// f.write_string(resp.body) or { panic(err) }
|
||||
// f.close()
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +39,11 @@ fn main() {
|
||||
go foo(10)
|
||||
go foo2(20)
|
||||
go foo3(30)
|
||||
$if is_coroutine ? {
|
||||
println('IS COROUTINE=true')
|
||||
} $else {
|
||||
println('IS COROUTINE=false')
|
||||
}
|
||||
for {
|
||||
println('hello from MAIN')
|
||||
coroutines.sleep(1 * time.second)
|
||||
|
@ -813,6 +813,8 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
|
||||
os.system('wget -O "${so_path}" "${so_url}"')
|
||||
println('done!')
|
||||
}
|
||||
res.compile_defines << 'is_coroutine'
|
||||
res.compile_defines_all << 'is_coroutine'
|
||||
} $else {
|
||||
println('coroutines only work on arm64 macos for now')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user