Sync actor

Rocket.syncFunction
sync(actor::A; withlock::Bool = true, timeout::Int = -1) where A
sync(factory::F; withlock::Bool = true, timeout::Int = -1) where { F <: AbstractActorFactory }

Creation operator for the SyncActor actor. Accepts optional named timeout argument which specifies maximum number of milliseconds to wait (throws SyncActorTimedOutException() on timeout). Also accepts optional withlock boolean flag indicating that every next!, error! and complete! event should be guarded with ReentrantLock.

Examples

using Rocket

actor  = keep(Int)
synced = sync(actor)

subscribe!(from(0:5, scheduler = AsyncScheduler()), synced)

yield()

wait(synced)
show(synced.actor.values)

# output
[0, 1, 2, 3, 4, 5]

Can also be used with an <: AbstractActorFactory as an argument. In this case sync function will return a special actor factory object, which will store all created actors in array and wrap them with a sync function. wait(sync_factory) method will wait for all of the created actors to be completed in the order of creation (but only once for each of them).

using Rocket

values = Int[]

factory  = lambda(on_next = (d) -> push!(values, d))
synced   = sync(factory)

subscribe!(from(0:5, scheduler = AsyncScheduler()), synced)

yield()

wait(synced)
show(values)

# output
[0, 1, 2, 3, 4, 5]

See also: SyncActor, AbstractActor

source
Rocket.SyncActorType
SyncActor{T, A}(actor::A; withlock::Bool = true, timeout::Int = -1) where { T, A }

Sync actor provides a synchronized interface to wait for an actor to be notified with a complete event. By default creates a re-entrant lock for synchronizing next!, error! and complete! events.

See also: Actor, sync

source