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_actor
— Functionas_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
— TypeAbstract type for all possible actor traits
See also: BaseActorTrait
, NextActorTrait
, ErrorActorTrait
, CompletionActorTrait
, InvalidActorTrait
Rocket.BaseActorTrait
— TypeBase actor trait specifies actor to listen for all next!
, error!
and complete!
events. BaseActorTrait
is a subtype of ActorTrait
.
See also: Actor
Rocket.NextActorTrait
— TypeNext actor trait specifies actor to listen for next!
events only. NextActorTrait
is a subtype of ActorTrait
.
See also: NextActor
Rocket.ErrorActorTrait
— TypeError actor trait specifies actor to listen for error!
events only. ErrorActorTrait
is a subtype of ActorTrait
.
See also: ErrorActor
Rocket.CompletionActorTrait
— TypeCompletion actor trait specifies actor to listen for complete!
events only. CompletionActorTrait
is a subtype of ActorTrait
.
See also: CompletionActor
Rocket.InvalidActorTrait
— TypeDefault 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
— TypeSupertype type for Actor
, NextActor
, ErrorActor
and CompletionActor
types.
See also: Actor
, NextActor
, ErrorActor
, CompletionActor
Rocket.Actor
— TypeCan 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
— TypeCan 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
— TypeCan 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
— TypeCan 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!
— Functionnext!(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!
— Functionerror!(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!
— Functioncomplete!(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!
— Functionon_next!(actor, data)
Both Actor and NextActor objects must implement its own method for on_next!
function which will be called on "next" event.
Rocket.on_error!
— Functionon_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!
— Functionon_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
— TypeAbstract type for all possible actor factories
See also: Actor
Rocket.create_actor
— Functioncreate_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
— TypeThis 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
— TypeThis error will be thrown if next!
, error!
or complete!
functions are called with invalid actor object
See also: next!
, error!
, complete!
, InvalidActorTrait
Rocket.InconsistentSourceActorDataTypesError
— TypeThis error will be thrown if next!
function is called with inconsistent data type
See also: AbstractActor
, Subscribable
, next!
Rocket.MissingDataArgumentInNextCall
— TypeThis error will be thrown if next!
function is called without data argument
See also: next!
Rocket.MissingErrorArgumentInErrorCall
— TypeThis error will be thrown if error!
function is called without err argument
See also: error!
Rocket.ExtraArgumentInCompleteCall
— TypeThis error will be thrown if complete!
function is called with extra data/err argument
See also: complete!
Rocket.MissingOnNextImplementationError
— TypeThis error will be thrown if Julia cannot find specific method of 'on_next!()' function for given actor and data
See also: on_next!
Rocket.MissingOnErrorImplementationError
— TypeThis error will be thrown if Julia cannot find specific method of 'on_error!()' function for given actor
See also: on_error!
Rocket.MissingOnCompleteImplementationError
— TypeThis error will be thrown if Julia cannot find specific method of 'on_complete!()' function for given actor and data
See also: on_next!