當前位置: 首頁>>代碼示例>>Java>>正文


Java Completable.subscribe方法代碼示例

本文整理匯總了Java中io.reactivex.Completable.subscribe方法的典型用法代碼示例。如果您正苦於以下問題:Java Completable.subscribe方法的具體用法?Java Completable.subscribe怎麽用?Java Completable.subscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.Completable的用法示例。


在下文中一共展示了Completable.subscribe方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: demo5

import io.reactivex.Completable; //導入方法依賴的package包/類
private void demo5() {
    Completable completable = Completable.fromAction(() -> {
        log("Let's do something");
    });

    completable.subscribe(() -> {
        log("Finished");
    }, throwable -> {
        log(throwable);
    });


    Single.just("One item")
            .subscribe((item) -> {
                log(item);
            }, (throwable) -> {
                log(throwable);
            });

    Maybe.empty();
    Maybe.just("Item")
            .subscribe(s -> {
                log("On Success: " + s);
            });

    Maybe.just("Item")
            .subscribe(s -> {
                log("On Success: " + s);
            }, throwable -> log("error"));

    Maybe.just("Item")
            .subscribe(
                    s -> log("success: " + s),
                    throwable -> log("error"),
                    () -> log("onComplete")
            );
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Android-Programming,代碼行數:38,代碼來源:MainActivity.java

示例2: gotPermissionSoStartUpdates

import io.reactivex.Completable; //導入方法依賴的package包/類
/**
 * Request location permissions and start updates
 * To be called from activity
 * Will perform early successful return if location manager arleady initialized
 *
 * @return
 */
public Completable gotPermissionSoStartUpdates() {
    //early successful return if updates arleady started (and somebode called us twice in row, it's possible because
    if (kalmanLocationManager!=null) {
        CustomLog.v(TAG,"Location updates arleady started");
        return Completable.create(s -> {
            s.onComplete();
        });
    }

    //no early return, perform real initialization
    Completable completable=initGNSS(gpsTime, netTime, filterTime)
            .subscribeOn(AndroidSchedulers.mainThread()) //we need looper here
            .observeOn(AndroidSchedulers.mainThread()) // We can touch in showMessage so...
            .cache();//cache result. we need it twice

    completable
            .subscribe(
                    () -> {
                        CustomLog.d(TAG,"Init done");
                        initDone=true;
                    },
                    s -> {
                        CustomLog.e(TAG,"Failed to init:"+s.toString()+" because "+s.getMessage());
                        CustomLog.logException(s);
                        stopSelf();
                        showMessage(s.getMessage());
                    });

    return completable;
}
 
開發者ID:intari,項目名稱:AndroidToolbox,代碼行數:38,代碼來源:GNSSLocationService.java

示例3: run

import io.reactivex.Completable; //導入方法依賴的package包/類
private void run(Completable completable) {
    completable.subscribe(() -> {}, errorHandler::handle);
}
 
開發者ID:e13mort,項目名稱:stf-console-client,代碼行數:4,代碼來源:StfCommander.java

示例4: shouldStartAShift

import io.reactivex.Completable; //導入方法依賴的package包/類
@Test
public void shouldStartAShift() throws Exception {

    Completable completable = shiftService.startAShift(shift);
    TestObserver testObserver = new TestObserver<>();

    completable.subscribe(testObserver);

    testObserver.assertNoErrors();
}
 
開發者ID:Ericliu001,項目名稱:RosterManager,代碼行數:11,代碼來源:ItemListActivityTest.java

示例5: main

import io.reactivex.Completable; //導入方法依賴的package包/類
public static void main(String[] args) {
	// TODO Auto-generated method stub
	Completable completable = Completable.fromAction(() -> System.out.println("Welcome to Completable"));
	completable.subscribe();

	
}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Programming-With-Java-9,代碼行數:8,代碼來源:DemoCompletable.java


注:本文中的io.reactivex.Completable.subscribe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。