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


Java Disposables.fromAction方法代码示例

本文整理汇总了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();
                    }
                });
            }
        }
    });
}
 
开发者ID:datalink747,项目名称:Rx_java2_soussidev,代码行数:22,代码来源:PreLollipopNetworkObservingStrategy.java

示例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();
          }
        });
      }
    }
  });
}
 
开发者ID:pwittchen,项目名称:ReactiveAirplaneMode,代码行数:28,代码来源:ReactiveAirplaneMode.java

示例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;
        }
    };
}
 
开发者ID:LouisJenkinsCS,项目名称:Code-Glosser,代码行数:36,代码来源:SwingScheduler.java

示例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);
    });
}
 
开发者ID:zakgof,项目名称:rxswt,代码行数:15,代码来源:SwtScheduler.java


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