本文整理汇总了Java中io.reactivex.disposables.Disposables.fromAction方法的典型用法代码示例。如果您正苦于以下问题:Java Disposables.fromAction方法的具体用法?Java Disposables.fromAction怎么用?Java Disposables.fromAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.disposables.Disposables
的用法示例。
在下文中一共展示了Disposables.fromAction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
});
}
}
});
}
示例2: 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();
}
});
}
}
});
}
示例3: createWorker
import io.reactivex.disposables.Disposables; //导入方法依赖的package包/类
@Override
public Worker createWorker() {
return new Worker() {
private boolean isDisposed = false;
@Override
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
LOG.fine("Inside of Scheduler");
int timeout = Math.min(Math.max(0, (int) unit.toMillis(delay)), Integer.MAX_VALUE);
isDisposed = false;
Timer timer = new Timer(timeout, e -> {
if (!isDisposed) {
run.run();
}
});
timer.setRepeats(false);
timer.start();
return Disposables.fromAction(() -> isDisposed = true);
}
@Override
public void dispose() {
LOG.finest("Disposing...");
isDisposed = true;
}
@Override
public boolean isDisposed() {
LOG.finest("IsDisposed called...");
return isDisposed;
}
};
}
示例4: schedule
import io.reactivex.disposables.Disposables; //导入方法依赖的package包/类
private Disposable schedule(Runnable action, Consumer<Runnable> executor) {
Disposable unitDisposable = new PrimitiveDisposable();
workerDisposable.add(unitDisposable);
executor.accept(() -> {
if (!unitDisposable.isDisposed() && !workerDisposable.isDisposed()) {
action.run();
}
workerDisposable.remove(unitDisposable);
});
return Disposables.fromAction(() -> {
unitDisposable.dispose();
workerDisposable.remove(unitDisposable);
});
}