Concurrency

> use("concurrency")
#<Atomy::Module 'concurrency.ay'>

me => Actor

Get the current actor.

Sending & Receiving

Actor <- v => Actor

Send message v to the actor.

Example:

> a = spawn: receive { 42 -> .ok } write
#<Actor:0x432cc>
> a <- 42
#<Actor:0x432cc>

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.

Example:

> a = spawn: receive { 1 -> .got-1 } write
#<Actor:0x43c30>
> a <- 0
#<Actor:0x43c30>
> a <- 2
#<Actor:0x43c30>
> a <- 1
#<Actor:0x43c30>

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>