本文整理汇总了Java中io.reactivex.Maybe.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Java Maybe.subscribe方法的具体用法?Java Maybe.subscribe怎么用?Java Maybe.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Maybe
的用法示例。
在下文中一共展示了Maybe.subscribe方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.reactivex.Maybe; //导入方法依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
Maybe<List<String>> month_maybe = Maybe.create(emitter -> {
try {
String[] monthArray = { "Jan", "Feb", "Mar", "Apl", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov",
"Dec" };
List<String> months = Arrays.asList(monthArray);
if (months != null && !months.isEmpty()) {
emitter.onSuccess(months);
} else {
emitter.onComplete();
}
} catch (Exception e) {
emitter.onError(e);
}
});
month_maybe.subscribe(s->System.out.println(s));
}
示例2: main
import io.reactivex.Maybe; //导入方法依赖的package包/类
public static void main(String[] args) {
// has emission
Maybe<Integer> presentSource = Maybe.just(100);
presentSource.subscribe(s -> System.out.println("Process 1 received:" + s),
Throwable::printStackTrace,
() -> System.out.println("Process 1 done!"));
//no emission
Maybe<Integer> emptySource = Maybe.empty();
emptySource.subscribe(s -> System.out.println("Process 2 received:" + s),
Throwable::printStackTrace,
() -> System.out.println("Process 2 done!"));
}
示例3: bind_whenSubscribingWithWorkerLifecycle_shouldMapToWorkerStopEvent
import io.reactivex.Maybe; //导入方法依赖的package包/类
@Test
public void bind_whenSubscribingWithWorkerLifecycle_shouldMapToWorkerStopEvent() {
BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.ACTIVE);
bind(lifecycle, worker);
verify(worker).onStart(argumentCaptor.capture());
Maybe observable = argumentCaptor.getValue().requestScope();
WorkerEventCallback callback = new WorkerEventCallback();
observable.subscribe(callback);
lifecycle.accept(InteractorEvent.INACTIVE);
assertThat(callback.getWorkerEvent()).isEqualTo(WorkerEvent.STOP);
}
示例4: bind_whenSubscribingWithWorkerLifecycle_shouldMapToWorkerStartEvent
import io.reactivex.Maybe; //导入方法依赖的package包/类
@Test
public void bind_whenSubscribingWithWorkerLifecycle_shouldMapToWorkerStartEvent() {
BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.ACTIVE);
bind(lifecycle, worker);
verify(worker).onStart(argumentCaptor.capture());
Maybe observable = argumentCaptor.getValue().requestScope();
WorkerEventCallback callback = new WorkerEventCallback();
observable.subscribe(callback);
lifecycle.accept(InteractorEvent.ACTIVE);
assertThat(callback.getWorkerEvent()).isEqualTo(WorkerEvent.START);
}
示例5: unbind_whenSubscribingWithWorkerLifecycle_shouldMapToWorkerStopEvent
import io.reactivex.Maybe; //导入方法依赖的package包/类
@Test
public void unbind_whenSubscribingWithWorkerLifecycle_shouldMapToWorkerStopEvent() {
BehaviorRelay<InteractorEvent> lifecycle = BehaviorRelay.createDefault(InteractorEvent.ACTIVE);
WorkerUnbinder unbinder = bind(lifecycle, worker);
verify(worker).onStart(argumentCaptor.capture());
Maybe observable = argumentCaptor.getValue().requestScope();
WorkerEventCallback callback = new WorkerEventCallback();
observable.subscribe(callback);
unbinder.unbind();
assertThat(callback.getWorkerEvent()).isEqualTo(WorkerEvent.STOP);
}