mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples: fix v build-examples
This commit is contained in:
@ -2,7 +2,7 @@ import sync
|
||||
import time
|
||||
|
||||
// Simulate expensive computing using sleep function
|
||||
fn expensive_computing(id, duration int, wg &sync.WaitGroup) {
|
||||
fn expensive_computing(id, duration int, mut wg sync.WaitGroup) {
|
||||
println('Executing expensive computing task (${id})...')
|
||||
time.sleep_ms(duration)
|
||||
println('Finish task ${id} on ${duration} ms')
|
||||
@ -10,11 +10,11 @@ fn expensive_computing(id, duration int, wg &sync.WaitGroup) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
wg := sync.new_waitgroup()
|
||||
mut wg := sync.new_waitgroup()
|
||||
wg.add(3)
|
||||
go expensive_computing(1, 100, wg)
|
||||
go expensive_computing(2, 500, wg)
|
||||
go expensive_computing(3, 1000, wg)
|
||||
go expensive_computing(1, 100, mut wg)
|
||||
go expensive_computing(2, 500, mut wg)
|
||||
go expensive_computing(3, 1000, mut wg)
|
||||
// Join all tasks
|
||||
wg.wait()
|
||||
println('All jobs finished!')
|
||||
|
@ -2,7 +2,7 @@ import net.http
|
||||
import sync
|
||||
import time
|
||||
|
||||
fn vlang_time(wg &sync.WaitGroup) ?string {
|
||||
fn vlang_time(mut wg sync.WaitGroup) ?string {
|
||||
start := time.ticks()
|
||||
data := http.get('https://vlang.io/utc_now')?
|
||||
finish := time.ticks()
|
||||
@ -12,7 +12,7 @@ fn vlang_time(wg &sync.WaitGroup) ?string {
|
||||
return data.text
|
||||
}
|
||||
|
||||
fn remote_ip(wg &sync.WaitGroup) ?string {
|
||||
fn remote_ip(mut wg sync.WaitGroup) ?string {
|
||||
start := time.ticks()
|
||||
data := http.get('https://api.ipify.org')?
|
||||
finish := time.ticks()
|
||||
@ -23,10 +23,10 @@ fn remote_ip(wg &sync.WaitGroup) ?string {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
wg := sync.new_waitgroup()
|
||||
mut wg := sync.new_waitgroup()
|
||||
wg.add(2)
|
||||
// Run tasks async
|
||||
go vlang_time(wg)
|
||||
go remote_ip(wg)
|
||||
go vlang_time(mut wg)
|
||||
go remote_ip(mut wg)
|
||||
wg.wait()
|
||||
}
|
||||
|
Reference in New Issue
Block a user