// V's model of concurrency is going to be very similar to Go's.
// Learn more about concurrency in the documentation:
// https://docs.spawnlang.dev/concepts/concurrency.html
import time
fn task(id int, duration int) {
println('task ${id} begin')
time.sleep(duration * time.millisecond)
println('task ${id} end')
}
fn main() {
// []thread is a special type that represents an array of threads
mut threads := []thread{}
// `spawn` starts a new thread and returns a `thread` object
// that can be added in thread array.
threads << spawn task(1, 500)
threads << spawn task(2, 900)
threads << spawn task(3, 100)
// `wait` is special function that waits for all threads to finish.
threads.wait()
println('done')
}// V's model of concurrency is going to be very similar to Go's.
// Learn more about concurrency in the documentation:
// https://docs.spawnlang.dev/concepts/concurrency.html
import time
fn task(id int, duration int) {
println('task ${id} begin')
time.sleep(duration * time.millisecond)
println('task ${id} end')
}
fn main() {
// []thread is a special type that represents an array of threads
mut threads := []thread{}
// `spawn` starts a new thread and returns a `thread` object
// that can be added in thread array.
threads << spawn task(1, 500)
threads << spawn task(2, 900)
threads << spawn task(3, 100)
// `wait` is special function that waits for all threads to finish.
threads.wait()
println('done')
}// Spawn's model of concurrency is going to be very similar to Go's.
// Learn more about concurrency in the documentation:
// https://docs.spawnlang.dev/concepts/concurrency.html
module main
import time
import runtime
fn task(id i32, duration u64) {
println('task ${id} begin')
time.sleep(duration * time.MILLISECOND)
println('task ${id} end')
}
fn main() {
// []runtime.Handle[unit] is a special type that represents an array of threads
mut threads := []&runtime.Handle[unit]{}
// `spawn` starts a new thread and returns a `runtime.Handle[unit]` object
// that can be added in thread array.
threads.push(spawn task(1, 500))
threads.push(spawn task(2, 900))
threads.push(spawn task(3, 100))
for thread in threads {
thread.join()
}
println('done')
}// Spawn's model of concurrency is going to be very similar to Go's.
// Learn more about concurrency in the documentation:
// https://docs.spawnlang.dev/concepts/concurrency.html
module main
import time
import runtime
fn task(id i32, duration u64) {
println('task ${id} begin')
time.sleep(duration * time.MILLISECOND)
println('task ${id} end')
}
fn main() {
// []runtime.Handle[unit] is a special type that represents an array of threads
mut threads := []&runtime.Handle[unit]{}
// `spawn` starts a new thread and returns a `runtime.Handle[unit]` object
// that can be added in thread array.
threads.push(spawn task(1, 500))
threads.push(spawn task(2, 900))
threads.push(spawn task(3, 100))
for thread in threads {
thread.join()
}
println('done')
}