Search in sources :

Example 76 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class ExecutorSchedulerTest method runnableDisposedAsyncTimed.

@Test(timeout = 1000)
public void runnableDisposedAsyncTimed() throws Exception {
    final Scheduler s = Schedulers.from(new Executor() {

        @Override
        public void execute(Runnable r) {
            new Thread(r).start();
        }
    });
    Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
    while (!d.isDisposed()) {
        Thread.sleep(1);
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) EmptyDisposable(io.reactivex.internal.disposables.EmptyDisposable)

Example 77 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class ExecutorSchedulerTest method runnableDisposedAsyncTimed2.

@Test(timeout = 1000)
public void runnableDisposedAsyncTimed2() throws Exception {
    ExecutorService executorScheduler = Executors.newScheduledThreadPool(1, new RxThreadFactory("TestCustomPoolTimed"));
    try {
        final Scheduler s = Schedulers.from(executorScheduler);
        Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
        while (!d.isDisposed()) {
            Thread.sleep(1);
        }
    } finally {
        executorScheduler.shutdownNow();
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) EmptyDisposable(io.reactivex.internal.disposables.EmptyDisposable)

Example 78 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class ExecutorSchedulerTest method runnableDisposedAsyncCrash.

@Test(timeout = 1000)
public void runnableDisposedAsyncCrash() throws Exception {
    final Scheduler s = Schedulers.from(new Executor() {

        @Override
        public void execute(Runnable r) {
            new Thread(r).start();
        }
    });
    Disposable d = s.scheduleDirect(new Runnable() {

        @Override
        public void run() {
            throw new IllegalStateException();
        }
    });
    while (!d.isDisposed()) {
        Thread.sleep(1);
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) EmptyDisposable(io.reactivex.internal.disposables.EmptyDisposable)

Example 79 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class SchedulerTest method disposeSelfPeriodicDirect.

@Test
public void disposeSelfPeriodicDirect() {
    final int[] count = { 0 };
    TestScheduler scheduler = new TestScheduler();
    final SequentialDisposable sd = new SequentialDisposable();
    Disposable d = scheduler.schedulePeriodicallyDirect(new Runnable() {

        @Override
        public void run() {
            count[0]++;
            sd.dispose();
        }
    }, 100, 100, TimeUnit.MILLISECONDS);
    sd.set(d);
    assertEquals(0, count[0]);
    assertFalse(d.isDisposed());
    scheduler.advanceTimeBy(400, TimeUnit.MILLISECONDS);
    assertEquals(1, count[0]);
    assertTrue(d.isDisposed());
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 80 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava-Android-Samples by kaushikgopal.

the class PaginationFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    _disposables = new CompositeDisposable();
    Disposable d2 = _paginator.onBackpressureDrop().concatMap(nextPage -> _itemsFromNetworkCall(nextPage + 1, 10)).observeOn(AndroidSchedulers.mainThread()).map(items -> {
        int start = _adapter.getItemCount() - 1;
        _adapter.addItems(items);
        _adapter.notifyItemRangeInserted(start, 10);
        _progressBar.setVisibility(View.INVISIBLE);
        return items;
    }).subscribe();
    // I'm using an Rxbus purely to hear from a nested button click
    // we don't really need Rx for this part. it's just easy ¯\_(ツ)_/¯
    Disposable d1 = _bus.asFlowable().subscribe(event -> {
        if (event instanceof PaginationAdapter.ItemBtnViewHolder.PageEvent) {
            int nextPage = _adapter.getItemCount() - 1;
            _paginator.onNext(nextPage);
        }
    });
    _disposables.add(d1);
    _disposables.add(d2);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) ButterKnife(butterknife.ButterKnife) RxBus(com.morihacky.android.rxjava.rxbus.RxBus) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) MainActivity(com.morihacky.android.rxjava.MainActivity) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ViewGroup(android.view.ViewGroup) BindView(butterknife.BindView) R(com.morihacky.android.rxjava.R) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) BaseFragment(com.morihacky.android.rxjava.fragments.BaseFragment) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Flowable(io.reactivex.Flowable) View(android.view.View) Nullable(android.support.annotation.Nullable) PublishProcessor(io.reactivex.processors.PublishProcessor) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

Disposable (io.reactivex.disposables.Disposable)224 Test (org.junit.Test)95 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)31 Logger (chat.rocket.android.helper.Logger)19 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 Worker (io.reactivex.Scheduler.Worker)15 List (java.util.List)14 Single (io.reactivex.Single)13 Function (io.reactivex.functions.Function)13 NonNull (io.reactivex.annotations.NonNull)12 Nullable (android.support.annotation.Nullable)11 Bundle (android.os.Bundle)10 CountingRunnable (io.reactivex.android.testutil.CountingRunnable)10 EmptyDisposable (io.reactivex.internal.disposables.EmptyDisposable)10 TestSubscriber (io.reactivex.subscribers.TestSubscriber)10 Optional (com.fernandocejas.arrow.optional.Optional)9 Schedulers (io.reactivex.schedulers.Schedulers)9 TimeUnit (java.util.concurrent.TimeUnit)8 NonNull (android.support.annotation.NonNull)7