Concurrency
> use("concurrency") #<Atomy::Module 'concurrency.ay'>
Sending & Receiving
Actor <- v => Actor
Send message v
to the actor.
receive: ~*branches
Receive a message sent to the current actor that matches any of the
patterns listed in branches
. Blocks until a matching message is
received. Non-matching messages are consumed and ignored.
receive { ~*branches } after(~timeout): ~*body
Similar to receive
, but with a timeout and an action to
perform if it times out.
Example:
> receive { 1 -> .ok } after(1): .too-slow .too-slow
Spawning
spawn &action => Actor
Spawn a new actor, performing action
.
Example:
> spawn: (2 + 2) write #<Actor:0x44ba4>
spawn-link &action => Actor
Spawn a new actor, performing action
, linked to the current
actor.
Example:
> spawn-link: (2 + 2) write #<Actor:0x450e0>