Java Code Examples for io.reactivex.FlowableEmitter#setCancellable()

The following examples show how to use io.reactivex.FlowableEmitter#setCancellable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxQuery.java    From ObjectBoxRxJava with Apache License 2.0 6 votes vote down vote up
static <T> void createListItemEmitter(final Query<T> query, final FlowableEmitter<T> emitter) {
    final DataSubscription dataSubscription = query.subscribe().observer(new DataObserver<List<T>>() {
        @Override
        public void onData(List<T> data) {
            for (T datum : data) {
                if (emitter.isCancelled()) {
                    return;
                } else {
                    emitter.onNext(datum);
                }
            }
            if (!emitter.isCancelled()) {
                emitter.onComplete();
            }
        }
    });
    emitter.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            dataSubscription.cancel();
        }
    });
}
 
Example 2
Source File: RxLocationFlowableOnSubscribe.java    From RxGps with Apache License 2.0 6 votes vote down vote up
@Override
public final void subscribe(FlowableEmitter<T> emitter) throws Exception {
    final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter));

    try {
        apiClient.connect();
    } catch (Throwable ex) {
        emitter.onError(ex);
    }

    emitter.setCancellable(() -> {
        if (apiClient.isConnected()) {
            onUnsubscribed(apiClient);
        }

        apiClient.disconnect();
    });
}
 
Example 3
Source File: ViewClickOnSubscribe.java    From dapp-wallet-demo with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(FlowableEmitter<View> emitter) throws Exception {
    verifyMainThread();
    View.OnClickListener listener = v -> {
        if (!emitter.isCancelled()){
            emitter.onNext(v);
        }
    };
    view.setOnClickListener(listener);
    emitter.setCancellable(() -> view.setOnClickListener(null));
}
 
Example 4
Source File: RxQuery.java    From objectbox-java with Apache License 2.0 5 votes vote down vote up
static <T> void createListItemEmitter(final Query<T> query, final FlowableEmitter<T> emitter) {
    final DataSubscription dataSubscription = query.subscribe().observer(data -> {
        for (T datum : data) {
            if (emitter.isCancelled()) {
                return;
            } else {
                emitter.onNext(datum);
            }
        }
        if (!emitter.isCancelled()) {
            emitter.onComplete();
        }
    });
    emitter.setCancellable(dataSubscription::cancel);
}
 
Example 5
Source File: JsonRpc2_0BesuRx.java    From web3j with Apache License 2.0 5 votes vote down vote up
private <T> void run(
        org.web3j.protocol.core.filters.Filter<T> filter,
        FlowableEmitter<? super T> emitter,
        long pollingInterval) {

    filter.run(scheduledExecutorService, pollingInterval);
    emitter.setCancellable(filter::cancel);
}
 
Example 6
Source File: JsonRpc2_0Rx.java    From web3j with Apache License 2.0 5 votes vote down vote up
private <T> void run(
        org.web3j.protocol.core.filters.Filter<T> filter,
        FlowableEmitter<? super T> emitter,
        long pollingInterval) {

    filter.run(scheduledExecutorService, pollingInterval);
    emitter.setCancellable(filter::cancel);
}
 
Example 7
Source File: ValueEventHandler.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void subscribe(final FlowableEmitter<VType> emitter) throws Exception
{
    emitter.setCancellable(new Subscription(emitter));
}
 
Example 8
Source File: AccessRightsEventHandler.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void subscribe(final FlowableEmitter<Boolean> emitter) throws Exception
{
    emitter.setCancellable(new Subscription(emitter));
}