本文整理匯總了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")
);
}
示例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;
}
示例3: run
import io.reactivex.Completable; //導入方法依賴的package包/類
private void run(Completable completable) {
completable.subscribe(() -> {}, errorHandler::handle);
}
示例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();
}
示例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();
}