All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rx.internal.operators.OnSubscribeFromCallable Maven / Gradle / Ivy

There is a newer version: 1.3.8
Show newest version
package rx.internal.operators;

import rx.Observable;
import rx.Subscriber;
import rx.exceptions.Exceptions;
import rx.internal.producers.SingleDelayedProducer;

import java.util.concurrent.Callable;

/**
 * Do not invoke the function until an Observer subscribes; Invokes function on each
 * subscription.
 * 

* Pass {@code fromCallable} a function, and {@code fromCallable} will call this function to emit result of invocation * afresh each time a new Observer subscribes. */ public final class OnSubscribeFromCallable implements Observable.OnSubscribe { private final Callable resultFactory; public OnSubscribeFromCallable(Callable resultFactory) { this.resultFactory = resultFactory; } @Override public void call(Subscriber subscriber) { final SingleDelayedProducer singleDelayedProducer = new SingleDelayedProducer(subscriber); subscriber.setProducer(singleDelayedProducer); try { singleDelayedProducer.setValue(resultFactory.call()); } catch (Throwable t) { Exceptions.throwIfFatal(t); subscriber.onError(t); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy