当前位置: 首页>>代码示例>>Java>>正文


Java Maybe.subscribe方法代码示例

本文整理汇总了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));
	
}
 
开发者ID:PacktPublishing,项目名称:Reactive-Programming-With-Java-9,代码行数:22,代码来源:DemoMaybe.java

示例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!"));
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:13,代码来源:Ch2_30.java

示例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);
}
 
开发者ID:uber,项目名称:RIBs,代码行数:13,代码来源:WorkerBinderTest.java

示例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);
}
 
开发者ID:uber,项目名称:RIBs,代码行数:13,代码来源:WorkerBinderTest.java

示例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);
}
 
开发者ID:uber,项目名称:RIBs,代码行数:15,代码来源:WorkerBinderTest.java


注:本文中的io.reactivex.Maybe.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。