Search in sources :

Example 6 with CompositeDisposable

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

the class SchedulerLifecycleTest method tryOutSchedulers.

private void tryOutSchedulers() throws InterruptedException {
    final CountDownLatch cdl = new CountDownLatch(4);
    final Runnable countAction = new Runnable() {

        @Override
        public void run() {
            cdl.countDown();
        }
    };
    CompositeDisposable csub = new CompositeDisposable();
    try {
        Worker w1 = Schedulers.computation().createWorker();
        csub.add(w1);
        w1.schedule(countAction);
        Worker w2 = Schedulers.io().createWorker();
        csub.add(w2);
        w2.schedule(countAction);
        Worker w3 = Schedulers.newThread().createWorker();
        csub.add(w3);
        w3.schedule(countAction);
        Worker w4 = Schedulers.single().createWorker();
        csub.add(w4);
        w4.schedule(countAction);
        if (!cdl.await(3, TimeUnit.SECONDS)) {
            fail("countAction was not run by every worker");
        }
    } finally {
        csub.dispose();
    }
}
Also used : Worker(io.reactivex.Scheduler.Worker) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 7 with CompositeDisposable

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

the class PollingFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _disposables = new CompositeDisposable();
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 8 with CompositeDisposable

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

the class RetrofitFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String githubToken = getResources().getString(R.string.github_oauth_token);
    _githubService = GithubService.createGithubService(githubToken);
    _disposables = new CompositeDisposable();
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Example 9 with CompositeDisposable

use of io.reactivex.disposables.CompositeDisposable 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)

Example 10 with CompositeDisposable

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

the class RxBusDemo_Bottom3Fragment method onStart.

@Override
public void onStart() {
    super.onStart();
    _disposables = new CompositeDisposable();
    ConnectableFlowable<Object> tapEventEmitter = _rxBus.asFlowable().publish();
    //
    _disposables.add(tapEventEmitter.subscribe(event -> {
        if (event instanceof RxBusDemoFragment.TapEvent) {
            _showTapText();
        }
    }));
    _disposables.add(tapEventEmitter.publish(stream -> stream.buffer(stream.debounce(1, TimeUnit.SECONDS))).observeOn(AndroidSchedulers.mainThread()).subscribe(taps -> {
        _showTapCount(taps.size());
    }));
    _disposables.add(tapEventEmitter.connect());
}
Also used : Bundle(android.os.Bundle) ButterKnife(butterknife.ButterKnife) LayoutInflater(android.view.LayoutInflater) ConnectableFlowable(io.reactivex.flowables.ConnectableFlowable) 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) TimeUnit(java.util.concurrent.TimeUnit) BaseFragment(com.morihacky.android.rxjava.fragments.BaseFragment) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Nullable(android.support.annotation.Nullable) CompositeDisposable(io.reactivex.disposables.CompositeDisposable)

Aggregations

CompositeDisposable (io.reactivex.disposables.CompositeDisposable)34 Nullable (android.support.annotation.Nullable)11 TimeUnit (java.util.concurrent.TimeUnit)10 Flowable (io.reactivex.Flowable)9 Test (org.junit.Test)9 NonNull (android.support.annotation.NonNull)6 TextUtils (android.text.TextUtils)6 Task (bolts.Task)6 TaskCompletionSource (bolts.TaskCompletionSource)6 RCLog (chat.rocket.android.log.RCLog)6 RxWebSocket (chat.rocket.android_ddp.rx.RxWebSocket)6 RxWebSocketCallback (chat.rocket.android_ddp.rx.RxWebSocketCallback)6 Consumer (io.reactivex.functions.Consumer)6 Bundle (android.os.Bundle)5 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)5 BindView (butterknife.BindView)5 ButterKnife (butterknife.ButterKnife)5 MainActivity (com.morihacky.android.rxjava.MainActivity)5