public final class Observables extends Object
Allows async methods to be converted into event-based Observable
s.
Modifier and Type | Method | Description |
---|---|---|
static <TResult> Observable<TResult> |
observe(MongoIterable<TResult> mongoIterable) |
Convert a
MongoIterable into an Observable . |
static <TResult> Observable<TResult> |
observe(Block<SingleResultCallback<TResult>> operation) |
Allows the conversion of
SingleResultCallback based operations into an Observable |
static <TResult> Observable<TResult> |
observeAndFlatten(Block<SingleResultCallback<List<TResult>>> operation) |
Allows the conversion of
SingleResultCallback based operations and flattens the results in an Observable . |
public static <TResult> Observable<TResult> observe(MongoIterable<TResult> mongoIterable)
MongoIterable
into an Observable
.TResult
- The type of result being observedmongoIterable
- the MongoIterable to subscribe topublic static <TResult> Observable<TResult> observe(Block<SingleResultCallback<TResult>> operation)
SingleResultCallback
based operations into an Observable
Requires a Block
that is passed the callback to be used with the operation.
This is required to make sure that the operation only occurs once the Subscription
signals for data.
A typical example would be when wrapping callback based methods to make them observable.
For example, converting MongoCollection.count(SingleResultCallback)
into an Observable
:
Observable<Long> countObservable = observe(new Block<SingleResultCallback<Long>>() {
public void apply(final SingleResultCallback<Long> callback) {
collection.countDocuments(callback);
}
});
TResult
- The type of result being observedoperation
- the block that implements the operation.public static <TResult> Observable<TResult> observeAndFlatten(Block<SingleResultCallback<List<TResult>>> operation)
SingleResultCallback
based operations and flattens the results in an Observable
.
Requires a Block
that is passed the callback to be used with the operation.
This is required to make sure that the operation only occurs once the Subscription
signals for data.
TResult
- The type of result being observedoperation
- the operation that is passed a callback and is used to delay execution of an operation until demanded.