threads
Implement basic threads:
// syntax is a to-do, too, a bit
//spawns a new thread with the identifier 'myname'. Thread names are optional
thread myname {
stuff1();
stuff2();
etc();
}
join myname; //joins a thread, no-op if thread has already finished
let x = 5;
let y = 6;
// captures variables for a thread. Currently unsure if it should actually move them or just copy
// Not really sure about syntax here
thread |x, y| {
print(x);
print(y);
}
// all threads are joined when the main script thread is about to finish to prevent threads being stopped unexpectedly
Development began in luciusmagn/nary-lang fork. The fork is highly experimental, so probably don't go there, lest you want your eyes to fall out
personally, a move would be a little counter intuitive. i think looking like ES here implies a copied value going to the thread. we can do some interesting things with mpsc to mock returning values from the threads.
let x = 1;
let t = thread |x| {
x+=100;
x
}
let x = t.join()
could make x == 101. i haven't quite worked all this out in my brain, but i have some general ideas floating around.
which lead me down this road: do we anticipate wanted something like futures/promises implemented on top of this later? i currently really like that rhai has no dependencies and trying to support .then() (or something similar) would require either bringing in tokio/mio or re-implementing an event loop manager ourselves.
i'm probably getting ahead of the task at hand, and we can always save that discussion for after 1.0.
i just read through #52 and #32 which basically answered all my questions. i'll work on a candidate for these.
Amazing. Some time ago, Jonathan wrote a microscopic actor framework called actress. He thought it might help. It is simple enough to just be included within Rhai (it's 88 lines with docs included). Might be worth checking out -> https://github.com/jonathandturner/actress