This PR redefines the transitions between a process states to be typed more semantically, and makes consumption of a single-message synchronous.
State transitions
State transitions before were the return value of a process, and there wasn't a clean way of exiting a process other than with exit(self()) which is not very elegant. They are now defined as follow:
type behavior('s) =
| Become('s)
| Suspend(int, 's)
| Terminate;
A Process may become[0] another Process (albeit preserving it's identifier)
A Process may suspend for some milliseconds before becoming (see 1)
A Process may terminate.
The definition of the procesess' behaviors seems to be simplified considerably, and from the shitty benchmarks I'm making (profiling and the examples themselves) it seems to be considerable faster and use less memory.
I attribute this to the reduced amount of closures.
[0] become is standard lingo in the literature of Actors for a state-change-by-continuation-passing.
Message Consumption
Whereas before the env.recv/1 function took a continuation that will be evaluated with a message as soon as one is found sometime in the future, the new env.recv/0 immediately returns with the next message to be consumed, or with None if the mailbox is empty.
This PR redefines the transitions between a process states to be typed more semantically, and makes consumption of a single-message synchronous.
State transitions
State transitions before were the return value of a process, and there wasn't a clean way of exiting a process other than with
exit(self())
which is not very elegant. They are now defined as follow:The definition of the procesess' behaviors seems to be simplified considerably, and from the shitty benchmarks I'm making (profiling and the examples themselves) it seems to be considerable faster and use less memory.
I attribute this to the reduced amount of closures.
[0] become is standard lingo in the literature of Actors for a state-change-by-continuation-passing.
Message Consumption
Whereas before the
env.recv/1
function took a continuation that will be evaluated with a message as soon as one is found sometime in the future, the newenv.recv/0
immediately returns with the next message to be consumed, or withNone
if the mailbox is empty.This means that code that used to look like
Now looks like:
Which we can simplify with operators that work on Options much nicely :)