Actors API

How to create a custom Actor

At first custom actor should implement a custom method for the as_actor function. Rocket.jl also provides a number of helper actor abstract types with predefined as_actor method behavior (see Traits API section). Optionally custom actor may implement a custom method for the is_exhausted function which is used to check if actor can handle any further message events.

using Rocket

struct MyCustomActor end

as_actor(::Type{<:MyCustomActor}) = Rocket.BaseActorTrait{Int}()

is_exhausted(actor::MyCustomActor) = # some custom logic here, false by default for all actors.

or

using Rocket

struct MyCustomActor <: Actor{Int} end # Automatically specifies BaseActorTrait{Int} behavior.

Additionally custom actor must provide a custom methods for on_next!, on_error! and/or on_complete! functions. Depending on specified actor trait behavior some methods may or may not be optional.

using Rocket

struct MyCustomActor <: Actor{Int} end

Rocket.on_next!(actor::MyCustomActor, data::Int)  = # custom logic here
Rocket.on_error!(actor::MyCustomActor, err)       = # custom logic here
Rocket.on_complete!(actor::MyCustomActor)         = # custom logic here

or

using Rocket

struct MyCustomCompletionActor <: CompletionActor{Int} end

Rocket.on_complete!(actor::MyCustomCompletionActor) = # custom logic here

Traits

Rocket.as_actorFunction
as_actor(::Type)

This function checks actor trait behavior specification. May be used explicitly to specify actor trait behavior for any object.

See also: ActorTrait

source
Rocket.InvalidActorTraitType

Default actor trait behavior for any object. Actor with such a trait specificaion cannot be used as a valid actor in subscribe! function. Doing so will raise an error.

source

Types

Events

Rocket.on_next!Function
on_next!(actor, data)

Both Actor and NextActor objects must implement its own method for on_next! function which will be called on "next" event.

See also: Actor, NextActor

source
Rocket.on_error!Function
on_error!(actor, err)

Both Actor and ErrorActor objects must implement its own method for on_error! function which will be called on "error" event.

See also: Actor, ErrorActor

source
Rocket.on_complete!Function
on_complete!(actor)

Both Actor and CompletionActor objects must implement its own method for on_complete! function which will be called on "complete" event.

See also: Actor, ErrorActor

source

Factory

Errors