Observables API

Any observable-like should implement a valid subscribable logic.

Traits

Rocket.as_subscribableFunction
as_subscribable(::Type)

This function checks subscribable trait behavior specification. Can be used explicitly to specify subscribable trait behavior for any object.

Examples

using Rocket

struct MyArbitraryType end
Rocket.as_subscribable(::Type{<:MyArbitraryType}) = ValidSubscribable{Int}()

println(as_subscribable(MyArbitraryType) ===ValidSubscribable{Int}())
;

# output
true

See also: subscribe!

source

Types

Rocket.SubscribableType

Super type for any subscribable object. Automatically specifies a ValidSubscribable trait behavior.

Examples

using Rocket

struct MySubscribable <: Subscribable{Int} end

println(Rocket.as_subscribable(MySubscribable) === ValidSubscribable{Int}())
;

# output

true

See also: SubscribableTrait, ValidSubscribable

source
Rocket.subscribe!Function
subscribe!(subscribable::T, actor::S) where T where S

subscribe! function is used to attach an actor to subscribable. It also checks types of subscribable and actors to be a valid Subscribable and Actor objects respectively. Passing not valid subscribable or/and actor object will throw an error.

Arguments

  • subscribable: valid subscribable object
  • actor: valid actor object

Examples

using Rocket

source = from((1, 2, 3))
subscribe!(source, logger())
;

# output

[LogActor] Data: 1
[LogActor] Data: 2
[LogActor] Data: 3
[LogActor] Completed
using Rocket

source = from((1, 2, 3))
subscribe!(source, 1)
;

# output

ERROR: Type Int64 is not a valid actor type.
[...]
using Rocket

source = from((1, 2, 3))
subscribe!(1, logger())
;

# output

ERROR: Type Int64 is not a valid subscribable type.
[...]

See also: on_subscribe!, as_subscribable

source
Rocket.on_subscribe!Function
on_subscribe!(subscribable, actor)

Each valid subscribable object have to define its own method for on_subscribe! function which specifies subscription logic and has return a valid Teardown object.

Arguments

  • subscribable: Subscribable object
  • actor: Actor object

Examples

using Rocket

struct MySubscribable <: Subscribable{Int} end

function Rocket.on_subscribe!(subscribable::MySubscribable, actor)
    next!(actor, 0)
    complete!(actor)
    return VoidTeardown()
end

subscribe!(MySubscribable(), logger())
;

# output

[LogActor] Data: 0
[LogActor] Completed

See also: Subscribable, Teardown, logger

source

Errors