当前位置: 首页>>代码示例>>Java>>正文


Java Disposables类代码示例

本文整理汇总了Java中io.reactivex.disposables.Disposables的典型用法代码示例。如果您正苦于以下问题:Java Disposables类的具体用法?Java Disposables怎么用?Java Disposables使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Disposables类属于io.reactivex.disposables包,在下文中一共展示了Disposables类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subscribe

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) {
  final FirebaseAuth.AuthStateListener listener = new FirebaseAuth.AuthStateListener() {
    @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
      if (!emitter.isDisposed()) {
        emitter.onNext(firebaseAuth);
      }
    }
  };

  instance.addAuthStateListener(listener);

  emitter.setDisposable(Disposables.fromAction(new Action() {
    @Override public void run() throws Exception {
      instance.removeAuthStateListener(listener);
    }
  }));
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:18,代码来源:AuthStateChangesOnSubscribe.java

示例2: schedule

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
    if (run == null) throw new NullPointerException("run == null");
    if (unit == null) throw new NullPointerException("unit == null");

    if (disposed) {
        return Disposables.disposed();
    }

    run = RxJavaPlugins.onSchedule(run);

    ScheduledRunnable scheduled = new ScheduledRunnable(handler, run);

    Message message = Message.obtain(handler, scheduled);
    message.obj = this; // Used as token for batch disposal of this worker's runnables.

    handler.sendMessageDelayed(message, Math.max(0L, unit.toMillis(delay)));

    // Re-check disposed state for removing in case we were racing a call to dispose().
    if (disposed) {
        handler.removeCallbacks(scheduled);
        return Disposables.disposed();
    }

    return scheduled;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:HandlerScheduler.java

示例3: disposeInUiThread

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
private Disposable disposeInUiThread(final Action action) {
    return Disposables.fromAction(new Action() {
        @Override public void run() throws Exception {
            if (Looper.getMainLooper() == Looper.myLooper()) {
                action.run();
            } else {
                final Scheduler.Worker inner = AndroidSchedulers.mainThread().createWorker();
                inner.schedule(new Runnable() {
                    @Override public void run() {
                        try {
                            action.run();
                        } catch (Exception e) {
                            onError("Could not unregister receiver in UI Thread", e);
                        }
                        inner.dispose();
                    }
                });
            }
        }
    });
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:22,代码来源:PreLollipopNetworkObservingStrategy.java

示例4: schedule

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
	if (run == null)
		throw new NullPointerException("run == null");
	if (unit == null)
		throw new NullPointerException("unit == null");

	if (disposed) {
		return Disposables.disposed();
	}

	run = RxJavaPlugins.onSchedule(run);

	ScheduledRunnable scheduled = new ScheduledRunnable(run);

	executeRunnable(title, delay, unit, scheduled);

	// Re-check disposed state for removing in case we were racing a
	// call to dispose().
	if (disposed) {
		return Disposables.disposed();
	}

	return scheduled;
}
 
开发者ID:SimonScholz,项目名称:RxSWT,代码行数:26,代码来源:EclipseScheduler.java

示例5: schedule

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
	if (run == null)
		throw new NullPointerException("run == null");
	if (unit == null)
		throw new NullPointerException("unit == null");

	if (disposed) {
		return Disposables.disposed();
	}

	run = RxJavaPlugins.onSchedule(run);

	ScheduledRunnable scheduled = new ScheduledRunnable(run);

	executeRunnable(display, delay, unit, scheduled);

	// Re-check disposed state for removing in case we were racing a
	// call to dispose().
	if (disposed) {
		return Disposables.disposed();
	}

	return scheduled;
}
 
开发者ID:SimonScholz,项目名称:RxSWT,代码行数:26,代码来源:DisplayScheduler.java

示例6: subscribe

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override
public void subscribe(final ObservableEmitter<DocumentSnapshot> emitter) throws Exception {
    final EventListener<DocumentSnapshot> listener = new EventListener<DocumentSnapshot>() {
        @Override
        public void onEvent(DocumentSnapshot documentSnapshot, FirebaseFirestoreException e) {
            if (!emitter.isDisposed()) {
                if (e == null) {
                    emitter.onNext(documentSnapshot);
                } else {
                    emitter.onError(e);
                }
            }
        }

    };

    registration = documentReference.addSnapshotListener(listener);

    emitter.setDisposable(Disposables.fromAction(new Action() {
        @Override
        public void run() throws Exception {
            registration.remove();
        }
    }));
}
 
开发者ID:btrautmann,项目名称:RxFirestore,代码行数:26,代码来源:DocumentSnapshotsOnSubscribe.java

示例7: openDatabase

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
public void openDatabase() {
    disposable = Observable.create((ObservableOnSubscribe<Realm>) emitter -> {
        final Realm observableRealm = Realm.getDefaultInstance();
        final RealmChangeListener<Realm> listener = realm -> {
            if(!emitter.isDisposed()) {
                emitter.onNext(observableRealm);
            }
        };
        observableRealm.addChangeListener(listener);
        emitter.setDisposable(Disposables.fromAction(() -> {
            observableRealm.removeChangeListener(listener);
            observableRealm.close();
        }));
        emitter.onNext(observableRealm);
    }).subscribeOn(looperScheduler.getScheduler()).unsubscribeOn(looperScheduler.getScheduler()).subscribe();
}
 
开发者ID:Zhuinden,项目名称:simple-stack,代码行数:17,代码来源:DatabaseManager.java

示例8: createResults

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
private Observable<List<Task>> createResults(QuerySelector<DbTask> querySelector) {
    return Observable.create((ObservableOnSubscribe<List<Task>>) emitter -> {
        Realm realm = Realm.getDefaultInstance();
        final RealmResults<DbTask> dbTasks = querySelector.createQuery(realm);
        final RealmChangeListener<RealmResults<DbTask>> realmChangeListener = element -> {
            if(element.isLoaded() && !emitter.isDisposed()) {
                List<Task> tasks = mapFrom(element);
                if(!emitter.isDisposed()) {
                    emitter.onNext(tasks);
                }
            }
        };
        emitter.setDisposable(Disposables.fromAction(() -> {
            if(dbTasks.isValid()) {
                dbTasks.removeChangeListener(realmChangeListener);
            }
            realm.close();
        }));
        dbTasks.addChangeListener(realmChangeListener);
    }).subscribeOn(looperScheduler.getScheduler()).unsubscribeOn(looperScheduler.getScheduler());
}
 
开发者ID:Zhuinden,项目名称:simple-stack,代码行数:22,代码来源:TaskRepository.java

示例9: disposeInUiThread

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
/**
 * Disposes an action in UI Thread
 *
 * @param dispose action to be executed
 * @return Disposable object
 */
private Disposable disposeInUiThread(final Action dispose) {
  return Disposables.fromAction(new Action() {
    @Override public void run() throws Exception {
      if (Looper.getMainLooper() == Looper.myLooper()) {
        dispose.run();
      } else {
        final Scheduler.Worker inner = AndroidSchedulers.mainThread().createWorker();
        inner.schedule(new Runnable() {
          @Override public void run() {
            try {
              dispose.run();
            } catch (Exception exception) {
              onError("Could not unregister receiver in UI Thread", exception);
            }
            inner.dispose();
          }
        });
      }
    }
  });
}
 
开发者ID:pwittchen,项目名称:ReactiveAirplaneMode,代码行数:28,代码来源:ReactiveAirplaneMode.java

示例10: subscribe

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override public void subscribe(final ObservableEmitter<DataSnapshot> emitter) {
  final ValueEventListener listener = new ValueEventListener() {
    @Override public void onDataChange(DataSnapshot dataSnapshot) {
      if (!emitter.isDisposed()) {
        emitter.onNext(dataSnapshot);
      }
    }

    @Override public void onCancelled(DatabaseError databaseError) {
      if (!emitter.isDisposed()) {
        emitter.onError(databaseError.toException());
      }
    }
  };

  ref.addValueEventListener(listener);
  emitter.setDisposable(Disposables.fromAction(new Action() {
    @Override public void run() throws Exception {
      ref.removeEventListener(listener);
    }
  }));
}
 
开发者ID:b3er,项目名称:RxFirebase2,代码行数:23,代码来源:DataChangesOnSubscribe.java

示例11: schedule

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override
public Disposable schedule(final Runnable action, long delayTime, TimeUnit unit) {
    if (innerSubscription.isDisposed()) {
        return Disposables.empty();
    }

    final ScheduledAction scheduledAction = new ScheduledAction(action, operationQueue);
    final ScheduledExecutorService executor = IOSScheduledExecutorPool.getInstance();

    Future<?> future;
    if (delayTime <= 0) {
        future = executor.submit(scheduledAction);
    } else {
        future = executor.schedule(scheduledAction, delayTime, unit);
    }

    scheduledAction.add(Disposables.fromFuture(future));
    scheduledAction.addParent(innerSubscription);

    return scheduledAction;
}
 
开发者ID:devjn,项目名称:RxiOSMOE,代码行数:22,代码来源:HandlerThreadScheduler.java

示例12: foundWithUnconditionalOnCompleteAfter

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Test
public void foundWithUnconditionalOnCompleteAfter() {
    new Observable<Integer>() {
        @Override
        protected void subscribeActual(Observer<? super Integer> s) {
            s.onSubscribe(Disposables.empty());
            s.onNext(10);
            s.onComplete();
        }
    }
    .compose(ObservableTransformers.indexOf(new Predicate<Integer>() {
        @Override
        public boolean test(Integer v) throws Exception {
            return v == 10;
        }
    }))
    .test()
    .assertResult(0L);
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:20,代码来源:ObservableIndexOfTest.java

示例13: SingleResponseReceiver

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
public SingleResponseReceiver(ClientCall<?, RespT> call) {
  this.call = call;

  this.source = new SingleSource<RespT>() {
    @Override
    public void subscribe(SingleObserver<? super RespT> observer) {
      responseObserver = observer;

      // todo which disposable should be used here
      observer.onSubscribe(Disposables.disposed());

      // start call until response gets subscribed
      startCall();

      if (error != null) {
        responseObserver.onError(error);
        error = null;
      }
    }
  };
}
 
开发者ID:xiaodongw,项目名称:grpc-rx,代码行数:22,代码来源:ClientCallsRx.java

示例14: subscribe

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
/**
 * @param emitter
 */
@Override
public void subscribe(final ObservableEmitter<FirebaseAuth> emitter) {
    final FirebaseAuth.AuthStateListener listener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (!emitter.isDisposed()) {
                emitter.onNext(firebaseAuth);
            }
        }
    };

    instance.addAuthStateListener(listener);

    emitter.setDisposable(Disposables.fromAction(new Action() {
        @Override
        public void run() throws Exception {
            instance.removeAuthStateListener(listener);
        }
    }));
}
 
开发者ID:yongjhih,项目名称:rxfirebase,代码行数:24,代码来源:AuthStateChangesOnSubscribe.java

示例15: subscribe

import io.reactivex.disposables.Disposables; //导入依赖的package包/类
@Override
public void subscribe(ObservableEmitter<Intent> emitter) throws Exception {
    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            emitter.onNext(intent);
        }
    };
    emitter.setDisposable(Disposables.fromRunnable(() -> { // thank you Jake W.
        try {
            if (contextWeakReference != null && contextWeakReference.get() != null) {
                contextWeakReference.get().unregisterReceiver(broadcastReceiver);
            }
        } catch (IllegalArgumentException ignored) {}
    }));

    if (contextWeakReference != null && contextWeakReference.get() != null) {
        contextWeakReference.get().registerReceiver(broadcastReceiver, intentFilter);
    }
}
 
开发者ID:alvinhkh,项目名称:buseta,代码行数:21,代码来源:RxBroadcastReceiver.java


注:本文中的io.reactivex.disposables.Disposables类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。