Giter Club home page Giter Club logo

setask's Introduction

SeTask

学习RxJava的平滑过渡库,主要用于Android场景,功能类似AsyncTask和Single。

基本使用

1. 导入仓库

maven { url 'https://jitpack.io' }

2. 添加依赖

compile 'com.github.senierr:SeTask:1.0.2'

普通订阅

Observable observable = Observable.create(new ObservableOnSubscribe<String>() {
    @Override
    public void subscribe(Emitter<String> emitter) throws Exception {
        emitter.isCancel();                         // 判断订阅是否终止
        emitter.onProcess("value");                 // 触发处理回调,不会终止订阅
        emitter.onComplete();                       // 触发结束/完成回调,并终止订阅
        emitter.onError(new Exception("Error"));    // 触发异常回调,并终止订阅
    }
})
        .bindToObservatory(observatory)     // 绑定至观察站
        .subscribe(new Observer<String>() {
            @Override
            public void onProcess(String value) {
                // 处理回调
            }

            @Override
            public void onComplete() {
                // 结束/完成回调
            }

            @Override
            public void onError(Exception e) {
                // 异常回调
            }
        });

计时订阅

Observable.interval(delay, period, timeUnit)
        .bindToObservatory(observatory)
        .subscribe(new Observer<Long>() {
            @Override
            public void onProcess(Long value) {
                log("onProcess: " + value);
            }
        });

延迟订阅

Observable.delay(delay, timeUnit)
        .bindToObservatory(observatory)
        .subscribe(new Observer<Long>() {
            @Override
            public void onComplete() {
                log("onComplete");
            }
        });

取消订阅

  • 单个取消订阅
observable.cancel();
  • 批量取消订阅
// 创建观察站
Observatory observatory = new Observatory();
// 绑定至观察站
observatory.bindToObservatory(observatory)
// 批量取消订阅
observatory.cancelAll();

setask's People

Contributors

senierr avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.