本文整理了Java中hu.akarnokd.rxjava2.interop.ZeroOneIterator
类的一些代码示例,展示了ZeroOneIterator
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZeroOneIterator
类的具体详情如下:
包路径:hu.akarnokd.rxjava2.interop.ZeroOneIterator
类名称:ZeroOneIterator
[英]Iterator that emits 0 or 1 values from a reactive source of Single, Maybe or Completable.
[中]迭代器,从单个、可能或可完成的反应源中发出0或1个值。
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
/**
* Returns a blocking Stream of the single success value of the source Single.
* @param <T> the value type
* @return the new Function to be used with {@code Single.to()}
*/
public static <T> Function<Single<T>, Stream<T>> toStream() {
return s -> {
ZeroOneIterator<T> zoi = new ZeroOneIterator<>();
s.subscribe(zoi);
return ZeroOneIterator.toStream(zoi);
};
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
@Override
public void onSuccess(T value) {
this.value = value;
countDown();
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
@Override
public T next() {
if (hasNext()) {
T v = value;
value = null;
return v;
}
throw new NoSuchElementException();
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
@Test
public void zeroOneDirectNever() {
ZeroOneIterator<Integer> z = Maybe.<Integer>never().subscribeWith(new ZeroOneIterator<>());
Assert.assertFalse(z.isDisposed());
z.dispose();
Assert.assertTrue(z.isDisposed());
}
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
@Override
public boolean hasNext() {
if (getCount() != 0) {
try {
await();
} catch (InterruptedException ex) {
dispose();
throw ExceptionHelper.wrapOrThrow(ex);
}
}
Throwable ex = error;
if (ex != null) {
throw ExceptionHelper.wrapOrThrow(ex);
}
return value != null;
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
@Test
public void zeroOneDirect() {
ZeroOneIterator<Integer> z = Maybe.just(1).subscribeWith(new ZeroOneIterator<>());
Assert.assertEquals(1, z.next().intValue());
try {
z.next();
Assert.fail("Should have thrown");
} catch (NoSuchElementException expected) {
// expected
}
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
/**
* Returns a blocking Stream of the elements of the Flowable.
* <p>
* Closing the Stream will cancel the flow.
* @param <T> the value type
* @return the Function to be used with {@code Flowable.to}.
*/
public static <T> Function<Flowable<T>, Stream<T>> toStream() {
return f -> ZeroOneIterator.toStream(f.blockingIterable().iterator());
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
/**
* Returns a blocking Stream of the elements of the Observable.
* <p>
* Closing the Stream will cancel the flow.
* @param <T> the value type
* @return the Function to be used with {@code Observable.to}.
*/
public static <T> Function<Observable<T>, Stream<T>> toStream() {
return f -> ZeroOneIterator.toStream(f.blockingIterable().iterator());
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
/**
* Returns a blocking Stream that waits for the Completable's terminal event.
* @param <T> the value type
* @return the Function to be used with {@code Completable.to()}
*/
public static <T> Function<Completable, Stream<T>> toStream() {
return c -> {
ZeroOneIterator<T> zoi = new ZeroOneIterator<>();
c.subscribe(zoi);
return ZeroOneIterator.toStream(zoi);
};
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
@Override
public void onError(Throwable e) {
this.error = e;
countDown();
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
/**
* Returns a blocking Stream of a potentially zero or one value (or error) of
* the Maybe.
* @param <T> the value type
* @return the Function to be used with {@code Maybe.to()}
*/
public static <T> Function<Maybe<T>, Stream<T>> toStream() {
return m -> {
ZeroOneIterator<T> zoi = new ZeroOneIterator<>();
m.subscribe(zoi);
return ZeroOneIterator.toStream(zoi);
};
}
代码示例来源:origin: akarnokd/RxJava2Jdk8Interop
@Override
public void onComplete() {
countDown();
}
内容来源于网络,如有侵权,请联系作者删除!