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).

using Rocket

struct MyCustomActor end

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

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(any)

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

See also: ActorTrait

source
Rocket.BaseActorTraitType

Base actor trait specifies actor to listen for all next!, error! and complete! events. BaseActorTrait is a subtype of ActorTrait.

See also: Actor

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. InvalidActorTrait is a subtype of ActorTrait.

See also: ActorTrait

source

Types

Rocket.ActorType

Can be used as a super type for common actor. Automatically specifies a BaseActorTrait trait behavior. Every Actor must implement its own methods for on_next!(actor, data), on_error!(actor, err) and on_complete!(actor) functions. Actor is a subtype of AbstractActor type.

Examples

using Rocket

struct MyActor <: Actor{String} end

Rocket.as_actor(MyActor)

# output

BaseActorTrait{String}()

See also: AbstractActor, as_actor, BaseActorTrait, ActorTrait, on_next!, on_error!, on_complete!

source
Rocket.NextActorType

Can be used as a super type for "next-only" actor. Automatically specifies a NextActorTrait trait behavior. Every NextActor must implement its own methods for on_next!(actor, data) function only. NextActor is a subtype of AbstractActor type.

Examples

using Rocket

struct MyNextActor <: NextActor{String} end

Rocket.as_actor(MyNextActor)

# output

NextActorTrait{String}()

See also: AbstractActor, as_actor, NextActorTrait, ActorTrait, on_next!

source
Rocket.ErrorActorType

Can be used as a super type for "error-only" actor. Automatically specifies a ErrorActorTrait trait behavior. Every ErrorActor must implement its own methods for on_error!(actor, err) function only. ErrorActor is a subtype of AbstractActor type.

Examples

using Rocket

struct MyErrorActor <: ErrorActor{String} end

Rocket.as_actor(MyErrorActor)

# output

ErrorActorTrait{String}()

See also: AbstractActor, as_actor, ErrorActorTrait, ActorTrait, on_error!

source
Rocket.CompletionActorType

Can be used as a super type for "completion-only" actor. Automatically specifies a CompletionActorTrait trait behavior. Every CompletionActor must implement its own methods for on_complete!(actor) function only. CompletionActor is a subtype of AbstractActor type.

Examples

using Rocket

struct MyCompletionActor <: CompletionActor{String} end

Rocket.as_actor(MyCompletionActor)

# output

CompletionActorTrait{String}()

See also: AbstractActor, as_actor, CompletionActorTrait, ActorTrait, on_complete!

source

Events

Rocket.next!Function
next!(actor, data)
next!(actor, data, scheduler)

This function is used to deliver a "next" event to an actor with some data. Takes optional scheduler object to schedule execution of data delivery.

See also: AbstractActor, on_next!

source
Rocket.error!Function
error!(actor, err)
error!(actor, err, scheduler)

This function is used to deliver a "error" event to an actor with some err. Takes optional scheduler object to schedule execution of error delivery.

See also: AbstractActor, on_error!

source
Rocket.complete!Function
complete!(actor)
complete!(actor, scheduler)

This function is used to deliver a "complete" event to an actor. Takes optional scheduler object to schedule execution of complete event delivery.

See also: AbstractActor, on_complete!

source
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, CompletionActor

source

Factory

Errors