Dyon uses the go keyword to create a concurrent coroutine, similar to Go, but with the difference that Dyon uses the return value.
Example:
fn foo() -> str {
sleep(1.0)
return "done"
}
fn main() {
foo_thread := go foo()
sleep(0.5)
val := join(thread: foo_thread)
if is_err(val) {
// An error happened when running the thread
println(unwrap_err(val))
} else {
// Prints `done`
println(unwrap(val))
}
}
To provide thread safety:
- Arguments are evaluated on the same stack
- Arguments are deep cloned over to the new run-time's stack
- Creating a fake AST call using expression references to the deep cloned arguments
- The thread evaluates the fake AST call on a new thread
- The remaining value on the new stack is the result
- The new result is deep cloned
Rules:
go foo() requires -> on the function foo
go foo(a, b) must have no lifetimes on arguments of foo, because the evaluated arguments are ordered by the call and do not necessarily have the same order in the lifetime check
Dyon uses the
gokeyword to create a concurrent coroutine, similar to Go, but with the difference that Dyon uses the return value.Example:
To provide thread safety:
Rules:
go foo()requires->on the functionfoogo foo(a, b)must have no lifetimes on arguments offoo, because the evaluated arguments are ordered by the call and do not necessarily have the same order in the lifetime check