package observers
- Alphabetic
- Public
- All
Type Members
- trait BufferedSubscriber[-A] extends Subscriber[A]
Interface describing Observer wrappers that are thread-safe (can receive concurrent events) and that return an immediate
Continue
when receivingonNext
events.Interface describing Observer wrappers that are thread-safe (can receive concurrent events) and that return an immediate
Continue
when receivingonNext
events. Meant to be used by data sources that cannot uphold the no-concurrent events and the back-pressure related requirements (i.e. data-sources that cannot wait onFuture[Ack]
for sending the next event).Implementations of this interface have the following contract:
onNext
/onError
/onComplete
of this interface MAY be called concurrentlyonNext
SHOULD return an immediateContinue
, as long as the buffer is not full and the underlying observer hasn't signaledStop
(N.B. due to the asynchronous nature,Stop
signaled by the underlying observer may be noticed later, so implementations of this interface make no guarantee about queued events - which could be generated, queued and dropped on the floor later)onNext
MUST return an immediateStop
result, after it notices that the underlying observer signaledStop
(due to the asynchronous nature of observers, this may happen later and queued events might get dropped on the floor)- in general the contract for the underlying Observer is fully respected (grammar, non-concurrent notifications, etc...)
- when the underlying observer canceled (by returning
Stop
), or when a concurrent upstream data source triggered an error, this SHOULD eventually be noticed and acted upon - as long as the buffer isn't full and the underlying observer
isn't
Stop
, then implementations of this interface SHOULD not lose events in the process - the buffer MAY BE either unbounded or bounded, in case of
bounded buffers, then an appropriate overflowStrategy needs to be set for
when the buffer overflows - either an
onError
triggered in the underlying observer coupled with aStop
signaled to the upstream data sources, or dropping events from the head or the tail of the queue, or attempting to apply back-pressure, etc...
See OverflowStrategy for the buffer policies available.
- final class CacheUntilConnectSubscriber[-A] extends Subscriber[A]
Wraps an
underlying
Subscriber into an implementation that caches all events until the call toconnect()
happens.Wraps an
underlying
Subscriber into an implementation that caches all events until the call toconnect()
happens. After being connected, the buffer is drained into theunderlying
observer, after which all subsequent events are pushed directly. - final class ConnectableSubscriber[-A] extends Subscriber[A]
Wraps a Subscriber into an implementation that abstains from emitting items until the call to
connect()
happens.Wraps a Subscriber into an implementation that abstains from emitting items until the call to
connect()
happens. Prior toconnect()
you can enqueue events for delivery onceconnect()
happens, but before any items emitted byonNext
/onComplete
andonError
.Example:
import monix.execution.Ack.Continue import monix.execution.Scheduler.Implicits.global val subscriber = new Subscriber[String] { val scheduler = global def onNext(a: String) = { println(s"Received: $$a") Continue } def onError(e: Throwable) = println(s"Error: $$e") def onComplete() = println("Completed!") } val out = ConnectableSubscriber(subscriber) // schedule onNext event, after connect() out.onNext("c") // schedule event "a" to be emitted first out.pushFirst("a") // schedule event "b" to be emitted second out.pushFirst("b") // underlying observer now gets events "a", "b", "c" in order out.connect()
Example of an observer ended in error:
val out2 = ConnectableSubscriber(subscriber) // schedule onNext event, after connect() out2.onNext("c") out2.pushFirst("a") // event "a" to be emitted first out2.pushFirst("b") // event "b" to be emitted second // schedule an onError sent downstream, once connect() // happens, but after "a" and "b" out2.pushError(new RuntimeException()) // underlying observer receives ... // onNext("a") -> onNext("b") -> onError(RuntimeException) out2.connect() // NOTE: that onNext("c") never happens
- final class SafeSubscriber[-A] extends Subscriber[A]
A safe subscriber safe guards subscriber implementations, such that:
A safe subscriber safe guards subscriber implementations, such that:
- the
onComplete
andonError
signals are back-pressured - errors triggered by downstream observers are caught and logged,
while the upstream gets an
Ack.Stop
, to stop sending events - once an
onError
oronComplete
was emitted, the observer no longer acceptsonNext
events, ensuring that the grammar is respected - if downstream signals a
Stop
, the observer no longer accepts any events, ensuring that the grammar is respected
- the
- trait Subscriber[-A] extends Observer[A]
A
Subscriber
is anObserver
with an attachedScheduler
.A
Subscriber
is anObserver
with an attachedScheduler
.A
Subscriber
can be seen as an address that the data source needs in order to send events, along with an execution context.
Value Members
- object BufferedSubscriber extends Builders with BuildersImpl with Serializable
- object CacheUntilConnectSubscriber extends Serializable
- object ConnectableSubscriber extends Serializable
- object SafeSubscriber extends Serializable
- object Subscriber extends Serializable
This is the API documentation for the Monix library.
Package Overview
monix.execution exposes lower level primitives for dealing with asynchronous execution:
Atomic
types, as alternative tojava.util.concurrent.atomic
monix.catnap exposes pure abstractions built on top of the Cats-Effect type classes:
monix.eval is for dealing with evaluation of results, thus exposing Task and Coeval.
monix.reactive exposes the
Observable
pattern:Observable
implementationsmonix.tail exposes Iterant for purely functional pull based streaming:
Batch
andBatchCursor
, the alternatives to Scala'sIterable
andIterator
respectively that we are using within Iterant's encodingYou can control evaluation with type you choose - be it Task, Coeval, cats.effect.IO or your own as long as you provide correct cats-effect or cats typeclass instance.