io.reactivex.Observable.zipArray()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(215)

本文整理了Java中io.reactivex.Observable.zipArray()方法的一些代码示例,展示了Observable.zipArray()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.zipArray()方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:zipArray

Observable.zipArray介绍

[英]Returns an Observable that emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of other ObservableSources.

zip applies this function in strict sequence, so the first item emitted by the new ObservableSource will be the result of the function applied to the first item emitted by each of the source ObservableSources; the second item emitted by the new ObservableSource will be the result of the function applied to the second item emitted by each of those ObservableSources; and so forth.

The resulting ObservableSource returned from zip will invoke onNext as many times as the number of onNext invocations of the source ObservableSource that emits the fewest items.

The operator subscribes to its sources in order they are specified and completes eagerly if one of the sources is shorter than the rest while disposing the other sources. Therefore, it is possible those other sources will never be able to run to completion (and thus not calling doOnComplete()). This can also happen if the sources are exactly the same length; if source A completes and B has been consumed and is about to complete, the operator detects A won't be sending further values and it will dispose B immediately. For example:

zip(new ObservableSource[]{range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2)}, (a) -> 
a)

action1 will be called but action2 won't.
To work around this termination property, use #doOnDispose(Action) as well or use using() to do cleanup in case of completion or a dispose() call.

Note on method signature: since Java doesn't allow creating a generic array with new T[], the implementation of this operator has to create an Object[] instead. Unfortunately, a Function passed to the method would trigger a ClassCastException.

Scheduler: zipArray does not operate by default on a particular Scheduler.
[中]返回一个Observable,该Observable发出指定组合器函数的结果,该函数应用于其他ObservableSource数组按顺序发出的项的组合。
zip以严格的顺序应用此函数,因此新ObservableSource发出的第一项将是应用于每个源ObservableSource发出的第一项的函数的结果;新的可观测资源发出的第二项将是应用于每个可观测资源发出的第二项的函数的结果;等等
从zip返回的结果ObservableSource调用onNext的次数与发出最少项的源ObservableSource的onNext调用次数相同。
操作员按指定的顺序订阅其源,如果其中一个源比其他源短,则在处理其他源时急切地完成。因此,这些其他源可能永远无法运行到完成(因此不调用doOnComplete()。如果源的长度完全相同,也可能发生这种情况;如果源A完成且B已被消耗且即将完成,则操作员检测到A不会发送更多值,并将立即处理B。例如:

zip(new ObservableSource[]{range(1, 5).doOnComplete(action1), range(6, 5).doOnComplete(action2)}, (a) -> 
a)

将调用action1,但不会调用action2。
要解决此终止属性,请同时使用#doOnDispose(Action)或使用using()在完成或dispose()调用时进行清理。
关于方法签名的注意事项:由于Java不允许使用新的t[]创建泛型数组,因此该操作符的实现必须创建一个对象[]。不幸的是,传递给该方法的函数将触发ClassCastException。
调度程序:zipArray默认情况下不会在特定调度程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void zipArrayEmpty() {
  assertSame(Observable.empty(), Observable.zipArray(Functions.<Object[]>identity(), false, 16));
}

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return zipArray(Functions.toFunction(zipper), delayError, bufferSize, source1, source2);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return zipArray(Functions.toFunction(zipper), delayError, bufferSize(), source1, source2);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return zipArray(Functions.toFunction(zipper), delayError, bufferSize, source1, source2);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source1, "source1 is null");
ObjectHelper.requireNonNull(source2, "source2 is null");
return zipArray(Functions.toFunction(zipper), delayError, bufferSize(), source1, source2);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source2, "source2 is null");
ObjectHelper.requireNonNull(source3, "source3 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source3, "source3 is null");
ObjectHelper.requireNonNull(source4, "source4 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source6, "source6 is null");
ObjectHelper.requireNonNull(source7, "source7 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source7, "source7 is null");
ObjectHelper.requireNonNull(source8, "source8 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source4, "source4 is null");
ObjectHelper.requireNonNull(source5, "source5 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5);

代码示例来源:origin: ReactiveX/RxJava

ObjectHelper.requireNonNull(source8, "source8 is null");
ObjectHelper.requireNonNull(source9, "source9 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8, source9);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source5, "source5 is null");
ObjectHelper.requireNonNull(source6, "source6 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source6, "source6 is null");
ObjectHelper.requireNonNull(source7, "source7 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7);

代码示例来源:origin: redisson/redisson

ObjectHelper.requireNonNull(source8, "source8 is null");
ObjectHelper.requireNonNull(source9, "source9 is null");
return zipArray(Functions.toFunction(zipper), false, bufferSize(), source1, source2, source3, source4, source5, source6, source7, source8, source9);

相关文章

Observable类方法