JuliaActors / YAActL.jl

Yet Another Actor Library, Concurrent Programming in Julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YAActL.jl

Yet another Actor Library: concurrent programming in Julia.

stable docs dev docs CI Coverage

YAActL is based on the Actor model. An actor

  • is a task running on a thread or a remote node which
  • receives messages over a channel and with it
  • dispatches a behavior function or one of its methods.

Actors can represent concurrently different and changing behaviors of real world or computational objects interacting with each other. This makes an actor system.

One Single Actor

using YAActL, Printf

# define two functions for printing a message
function pr(msg)
    print(@sprintf("%s\n", msg))
    become(pr, "Next") # change behavior
end
pr(info, msg) = print(@sprintf("%s: %s\n", info, msg))

# a function for doing arithmetic
calc(op::F, x, y) where F<:Function = op(x, y)

# start an actor with the first behavior
myactor = Actor(pr)

Now we can interact with it:

julia> cast!(myactor, "My first actor")     # send a message to it
My first actor

julia> cast!(myactor, "Something else")     # send again a message
Next: Something else

julia> become!(myactor, pr, "New behavior") # change the behavior to another one

julia> cast!(myactor, "bla bla bla")        # and send again a message
New behavior: bla bla bla

The actor can also change to a completely different behavior and do some arithmetic:

julia> become!(myactor, calc, +, 10);       # now become a machine for adding to 10

julia> call!(myactor, 5)                    # send a request to add 5 to it and to return the result
15

julia> become!(myactor, ^);                 # become an exponentiation machine

julia> call!(myactor, 123, 456)             # try it
2409344748064316129

Rationale

  1. Actors are an important concept for concurrent computing.
  2. There is no actor library in Julia.
  3. Julia allows to condense the actor-concept into a smart and fast library.
  4. A community effort is needed to do it.

If you agree with those points, please help with YAActL's development.

About

Yet Another Actor Library, Concurrent Programming in Julia

License:MIT License


Languages

Language:Julia 100.0%