Defer Observable

defer(::Type{D}, factoryFn::F) where { D, F <: Function }

Creates an Observable that, on subscribe, calls an Observable factory to make an Observable for each new Observer.


  • T: type of output data source, created by the factoryFn
  • factoryFn: the Observable factory function to invoke for each Observer that subscribes to the output Observable


using Rocket

source = defer(Int, () -> from([ 1, 2, 3 ]))

subscribe!(source, logger())

# output
[LogActor] Data: 1
[LogActor] Data: 2
[LogActor] Data: 3
[LogActor] Completed

See also: Subscribable, subscribe!, logger



defer allows you to create the Observable only when the Actor subscribes, and create a fresh Observable for each Actor. It waits until an Actor subscribes to it, and then it generates an Observable, typically with an Observable factory function. It does this afresh for each subscriber, so although each subscriber may think it is subscribing to the same Observable, in fact each subscriber gets its own individual Observable.