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


Java Disposable.dispose方法代码示例

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


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

示例1: test0

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Override
public void test0() {
    Log.i(TAG, "test0() Interval simple demo");
    final Disposable disposable = Observable.interval(1, TimeUnit.SECONDS, Schedulers.computation())
            .subscribe(new Consumer<Long>() {
                @Override
                public void accept(Long aLong) throws Exception {
                    Log.d(TAG, "Consumer<String> accept() aLong: " + aLong);
                }
            });
    // sleep 3 seconds
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // dispose
    Log.d(TAG, "test0() disposable.dispose()");
    disposable.dispose();
}
 
开发者ID:afunx,项目名称:RxJava4AndroidDemos,代码行数:21,代码来源:Interval.java

示例2: workerDispose

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void workerDispose() throws Exception {
    Task t = new Task(1);

    Worker w = SwingSchedulers.edt().createWorker();
    try {
        Disposable d = w.schedule(t, 500, TimeUnit.MILLISECONDS);

        Thread.sleep(100);

        d.dispose();

        Thread.sleep(500);

        Assert.assertEquals(0, t.calls);
    } finally {
        w.dispose();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Swing,代码行数:20,代码来源:SwingSchedulersTest.java

示例3: main

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
public static void main(String[] args) {
    Disposable d = Observable.interval(1, TimeUnit.SECONDS)
            .doOnDispose(() -> System.out.println("Disposing on thread"
                            + Thread.currentThread().getName()))
            .subscribe(i -> System.out.println("Received " +
                    i));
    sleep(3000);
    d.dispose();
    sleep(3000);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:11,代码来源:Ch6_19.java

示例4: main

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
public static void main(String[] args) {
        Observable<Long> seconds =
                Observable.interval(1, TimeUnit.SECONDS);
        Disposable disposable =
                seconds.subscribe(l -> System.out.println("Received: " + l));
//sleep 5 seconds
        sleep(5000);
//dispose and stop emissions
        disposable.dispose();
//sleep 5 seconds to prove
//there are no more emissions
        sleep(5000);
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:14,代码来源:Ch2_33.java

示例5: directScheduleOnceDisposedDoesNotRun

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void directScheduleOnceDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.scheduleDirect(counter);
    disposable.dispose();

    runUiThreadTasks();
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:HandlerSchedulerTest.java

示例6: directScheduleOnceWithDelayDisposedDoesNotRun

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void directScheduleOnceWithDelayDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.scheduleDirect(counter, 1, MINUTES);

    idleMainLooper(30, SECONDS);
    disposable.dispose();

    idleMainLooper(30, SECONDS);
    runUiThreadTasks();
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:HandlerSchedulerTest.java

示例7: workerScheduleOnceDisposedDoesNotRun

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void workerScheduleOnceDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();

    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter);
    disposable.dispose();

    runUiThreadTasks();
    assertEquals(0, counter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:HandlerSchedulerTest.java

示例8: test0

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Override
public void test0() {
    Log.i(TAG, "test0() Debounce simple demo, interval(100, TimeUnit.MILLISECONDS).debounce(100, TimeUnit.MILLISECONDS)");
    Disposable disposable = Observable.interval(100, TimeUnit.MILLISECONDS)
            .debounce(100, TimeUnit.MILLISECONDS)
            .subscribe(new Consumer<Long>() {
                @Override
                public void accept(Long l) throws Exception {
                    Log.d(TAG, "Consumer<Long> accept() l: " + l);
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    Log.d(TAG, "Consumer<Throwable> accept() throwable: " + throwable);
                }
            }, new Action() {
                @Override
                public void run() throws Exception {
                    Log.d(TAG, "Action run() for onComplete()");
                }
            });
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // dispose
    Log.d(TAG, "test0() disposable.dispose()");
    disposable.dispose();
}
 
开发者ID:afunx,项目名称:RxJava4AndroidDemos,代码行数:31,代码来源:Debounce.java

示例9: bind

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void bind() throws Exception {
    ObservableList<String> origList = RxCollections.of(new ArrayList<>());
    javafx.collections.ObservableList<String> fxList = FXCollections.observableList(new ArrayList<>());
    Disposable listBinding = RxCollectionsFX.bind(origList, fxList);
    String str = "Hello world!";
    origList.add(str);
    assertEquals(fxList.get(0), str);
    listBinding.dispose();
}
 
开发者ID:FHannes,项目名称:RxJavaCollections,代码行数:11,代码来源:RxCollectionsFXTest.java

示例10: detachView

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Override
public void detachView() {
    for (Disposable disposable : disposables) {
        if (!disposable.isDisposed()) disposable.dispose();
    }
    mView = null;
}
 
开发者ID:vsona,项目名称:RxJava2RetrofitDemo,代码行数:8,代码来源:BasePresenter.java

示例11: clearQueue

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
public void clearQueue() {
    Log.d(TAG, "clearQueue: size to be cleared=" + mLoadingDetections.size());
    // For each of the loading detections dispose it and remove it. Fuck em off
    Iterator<Map.Entry<String, Disposable>> iterator = mLoadingDetections.entrySet().iterator();

    while (iterator.hasNext()) {
        Map.Entry<String, Disposable> entry = iterator.next();

        Disposable disposable = entry.getValue();
        if (!disposable.isDisposed()) {
            disposable.dispose();
        }
        iterator.remove();
    }
}
 
开发者ID:dvdciri,项目名称:DeepImagePreview-Project,代码行数:16,代码来源:SearchResultHandler.java

示例12: downloadProducts

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void downloadProducts() throws Exception {
  String category = faker.numerify("category-##");
  //insert sample data into es
  List<Product> sampleProducts = IntStream.range(1, 5).mapToObj(index -> {
    Product product = createProduct(category);
    try {
      productDao.upsertProduct(product);
    } catch (InvalidProtocolBufferException e) {
      log.error(" error on creating sample product for test downloadProducts", e);
    }
    return product;
  }).collect(Collectors.toList());

  esClient.admin().indices().flush(Requests.flushRequest(INDEX)).actionGet();
  PublishSubject<Product> productPublishSubject = PublishSubject.create();
  List<Product> downloadedProducts = Lists.newArrayList();
  Disposable disposable = productPublishSubject
      .doOnNext(product -> downloadedProducts.add(product))
      .doOnError(t -> fail("should not failed", t))
      .doOnComplete(() -> {
        Product[] downloadedProductArray = sampleProducts.toArray(new Product[]{});
        assertThat(downloadedProducts).containsOnly(downloadedProductArray);
      })
      .subscribe();
  productDao.downloadProducts(
      DownloadProductsRequest.newBuilder()
          .setCategory(category)
          .build(),
      productPublishSubject
  );
  disposable.dispose();
}
 
开发者ID:email2liyang,项目名称:grpc-mate,代码行数:34,代码来源:ProductDaoTest.java

示例13: testHotObservable

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void testHotObservable() throws Exception {

    ConnectableObservable<Long> connectableObservable = Observable.interval(1,
            TimeUnit.SECONDS,
            Schedulers.from(executorService)).publish();

    connectableObservable.subscribe(x -> System.out.println("L1:" + x));

    Thread.sleep(2000);

    Disposable disposable = connectableObservable.connect(); //Let us begin

    connectableObservable.subscribe(x -> System.out.println("L2:" + x));

    Thread.sleep(2000);

    connectableObservable.subscribe(x -> System.out.println("L3:" + x));

    disposable.dispose();

    Thread.sleep(10000);
}
 
开发者ID:dhinojosa,项目名称:rxjavatraining,代码行数:24,代码来源:HotVsColdObservableTest.java

示例14: testSceneLifecycleMultiObserver

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void testSceneLifecycleMultiObserver() throws Exception {
  stage.start();

  Scene scene = new DumpScene();
  stage.pushScene(scene);
  Observable<Integer> lifecycle = SceneLifecycle.create(scene);

  RecordConsumer consumer1 = new RecordConsumer();
  Disposable disposable1 = lifecycle.subscribe(consumer1);
  SceneCalling calling1 = new SceneCalling();

  calling1.onCreate++;
  calling1.onCreateView++;
  calling1.onAttachView++;
  calling1.onStart++;
  consumer1.assertSceneCalling(calling1);

  stage.resume();
  calling1.onResume++;
  consumer1.assertSceneCalling(calling1);

  RecordConsumer consumer2 = new RecordConsumer();
  Disposable disposable2 = lifecycle.subscribe(consumer2);
  SceneCalling calling2 = new SceneCalling();

  calling2.onCreate++;
  calling2.onCreateView++;
  calling2.onAttachView++;
  calling2.onStart++;
  calling2.onResume++;
  consumer2.assertSceneCalling(calling2);

  stage.pause();
  calling1.onPause++;
  consumer1.assertSceneCalling(calling1);
  calling2.onPause++;
  consumer2.assertSceneCalling(calling2);

  assertFalse(disposable1.isDisposed());
  disposable1.dispose();
  assertTrue(disposable1.isDisposed());
  stage.resume();
  consumer1.assertSceneCalling(calling1);
  calling2.onResume++;
  consumer2.assertSceneCalling(calling2);

  assertFalse(disposable2.isDisposed());
  disposable2.dispose();
  assertTrue(disposable2.isDisposed());
  stage.pause();
  consumer1.assertSceneCalling(calling1);
  consumer2.assertSceneCalling(calling2);
}
 
开发者ID:seven332,项目名称:Stage,代码行数:55,代码来源:SceneLifecycleTest.java

示例15: testThrashSubscriptions

import io.reactivex.disposables.Disposable; //导入方法依赖的package包/类
@Test
public void testThrashSubscriptions() throws InterruptedException, ExecutionException
{
    final AtomicInteger globalCounter = new AtomicInteger(0);
    final int subscriberCount = 25;
    ExecutorService executorService = Executors.newFixedThreadPool(subscriberCount);

    for (int j = 0; j < subscriberCount; ++j) {
        System.gc();

        final AtomicInteger counter = new AtomicInteger(0);
        final Flowable<Integer> valueObservable = source.get("test");

        final Callable<Disposable> queryCallable = new Callable<Disposable>() {

            final int index = globalCounter.incrementAndGet();

            @Override
            public Disposable call() throws Exception
            {
                return valueObservable.subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer)
                    {
                        counter.incrementAndGet();
                    }
                });
            }
        };
        List<Callable<Disposable>> callables = new ArrayList<>();

        for (int i = 0; i < subscriberCount; ++i) {
            callables.add(queryCallable);
        }

        List<Future<Disposable>> futures = executorService.invokeAll(callables);
        List<Disposable> subscriptions = new ArrayList<>();

        for (int i = 0; i < subscriberCount; ++i) {
            subscriptions.add(futures.get(i).get());
        }

        source.onNext("test", 1);

        for (int i = 0; i < 10; ++i) {
            if (counter.get() != subscriberCount) {
                Thread.sleep(10);
            }
        }

        assertEquals(subscriberCount, counter.get());

        for (int i = 0; i < subscriberCount; ++i) {
            Disposable subscription = subscriptions.get(i);

            subscription.dispose();
        }
    }
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:60,代码来源:SubjectMapTest.java


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