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 hereor
using Rocket
struct MyCustomCompletionActor <: CompletionActor{Int} end
Rocket.on_complete!(actor::MyCustomCompletionActor) = # custom logic hereTraits
Rocket.as_actor — Function
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
Rocket.ActorTrait — Type
Abstract type for all possible actor traits
See also: BaseActorTrait, NextActorTrait, ErrorActorTrait, CompletionActorTrait, InvalidActorTrait
Rocket.BaseActorTrait — Type
Rocket.NextActorTrait — Type
Rocket.ErrorActorTrait — Type
Error actor trait specifies actor to listen for error! events only. ErrorActorTrait is a subtype of ActorTrait.
See also: ErrorActor
Rocket.CompletionActorTrait — Type
Completion actor trait specifies actor to listen for complete! events only. CompletionActorTrait is a subtype of ActorTrait.
See also: CompletionActor
Rocket.InvalidActorTrait — Type
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
Types
Rocket.AbstractActor — Type
Supertype type for Actor, NextActor, ErrorActor and CompletionActor types.
See also: Actor, NextActor, ErrorActor, CompletionActor
Rocket.Actor — Type
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!
Rocket.NextActor — Type
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!
Rocket.ErrorActor — Type
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!
Rocket.CompletionActor — Type
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!
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!
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!
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!
Rocket.on_next! — Function
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
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
Factory
Rocket.AbstractActorFactory — Type
Rocket.create_actor — Function
create_actor(::Type{L}, factory::F) where { L, F <: AbstractActorFactory }Actor creator function for a given factory F. Should be implemented explicitly for any AbstractActorFactory object
See also: AbstractActorFactory, MissingCreateActorFactoryImplementationError
Rocket.MissingCreateActorFactoryImplementationError — Type
This error will be throw if Julia cannot find specific method of 'create_actor()' function for given actor factory
See also: AbstractActorFactory, create_actor
Errors
Rocket.InvalidActorTraitUsageError — Type
This error will be thrown if next!, error! or complete! functions are called with invalid actor object
See also: next!, error!, complete!, InvalidActorTrait
Rocket.InconsistentSourceActorDataTypesError — Type
This error will be thrown if next! function is called with inconsistent data type
See also: AbstractActor, Subscribable, next!