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

examples: add http.get and file writes to the coroutines example

This commit is contained in:
Alexander Medvednikov 2023-06-12 13:05:59 +03:00
parent 54eabcb242
commit f73e99cddd

View File

@ -1,5 +1,5 @@
// Build with
// v -use-coroutines simple_coroutines.v
// v -gc none -use-coroutines simple_coroutines.v
//
import coroutines
import time
@ -21,12 +21,11 @@ fn foo2(a int) {
// C.printf(c'hello from foo2() a=%d\n', 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()
resp := http.get('https://vlang.io/utc_now') 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()
}
}