Petr
Petr
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
next week
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
btw this particular example has nothing similar to the Go model as stated in the comment 😄
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
another version with results
// 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) -> i32 {
println('task ${id} begin')
time.sleep(duration * time.MILLISECOND)
println('task ${id} end')
return id
}

fn main() {
// []runtime.Handle[i32] is a special type that represents an array of threads
mut threads := []&runtime.Handle[i32]{}

// `spawn` starts a new thread and returns a `runtime.Handle[i32]` 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))

res := threads.map(|t| t.join().unwrap_or(0))
println('result: ${res}')

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) -> i32 {
println('task ${id} begin')
time.sleep(duration * time.MILLISECOND)
println('task ${id} end')
return id
}

fn main() {
// []runtime.Handle[i32] is a special type that represents an array of threads
mut threads := []&runtime.Handle[i32]{}

// `spawn` starts a new thread and returns a `runtime.Handle[i32]` 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))

res := threads.map(|t| t.join().unwrap_or(0))
println('result: ${res}')

println('done')
}
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
can you create an issue for this case? we need an error about not instantiated use of generic struct []runtime.Handle{}
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
and push instead <<
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
oops. you need runtime.Handle[unit]
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
And you need to call join in loop on this array of handles
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
Use runtime.Handle as array type
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
assert is not implemented yet
23 replies
TSPThe Spawn Programming Language
Created by YUART on 6/17/2024 in #❓・help
YUART - How to implement this code in Spawn?...
Use t.assert_eq instead assert
23 replies
TSPThe Spawn Programming Language
Created by B1Z0N on 3/24/2024 in #❓・help
B1Z0N - Compiled V, then Spawn from main [repo]...
./spawnlang ./examples/do.sp in compiler dir should work fine as well
8 replies
TSPThe Spawn Programming Language
Created by B1Z0N on 3/24/2024 in #❓・help
B1Z0N - Compiled V, then Spawn from main [repo]...
Can you try compiling outside the compiler directory?
8 replies
TSPThe Spawn Programming Language
Created by B1Z0N on 3/24/2024 in #❓・help
B1Z0N - Compiled V, then Spawn from main [repo]...
reproduced
8 replies
TSPThe Spawn Programming Language
Created by B1Z0N on 3/24/2024 in #❓・help
B1Z0N - Compiled V, then Spawn from main [repo]...
Hmmm, interesting, I'll check it on my Linux machine now
8 replies