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


Java UnicastProcessor.create方法代码示例

本文整理汇总了Java中io.reactivex.processors.UnicastProcessor.create方法的典型用法代码示例。如果您正苦于以下问题:Java UnicastProcessor.create方法的具体用法?Java UnicastProcessor.create怎么用?Java UnicastProcessor.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.processors.UnicastProcessor的用法示例。


在下文中一共展示了UnicastProcessor.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toStreamCancel

import io.reactivex.processors.UnicastProcessor; //导入方法依赖的package包/类
@Test
public void toStreamCancel() {
    UnicastProcessor<Integer> up = UnicastProcessor.create();

    up.onNext(1);
    up.onNext(2);
    up.onNext(3);
    up.onNext(4);
    up.onNext(5);

    try (Stream<Integer> s = up
            .to(FlowableInterop.toStream()).limit(3)) {
        Assert.assertTrue(up.hasSubscribers());

        List<Integer> list = s.collect(Collectors.toList());
        Assert.assertEquals(Arrays.asList(1, 2, 3), list);
    }

    Assert.assertFalse(up.hasSubscribers());
}
 
开发者ID:akarnokd,项目名称:RxJava2Jdk8Interop,代码行数:21,代码来源:FlowableInteropTest.java

示例2: mapOptionalAsyncFused

import io.reactivex.processors.UnicastProcessor; //导入方法依赖的package包/类
@Test
public void mapOptionalAsyncFused() {
    TestSubscriber<Integer> ts = TestHelper.fusedSubscriber(QueueSubscription.ANY);

    UnicastProcessor<Integer> up = UnicastProcessor.create();
    TestHelper.emit(up, 1, 2, 3, 4, 5);

    up
    .compose(FlowableInterop.mapOptional(v -> {
        if (v % 2 == 0) {
            return Optional.of(-v);
        }
        return Optional.empty();
    }))
    .subscribeWith(ts)
    .assertOf(TestHelper.assertFusedSubscriber(QueueSubscription.ASYNC))
    .assertResult(-2, -4);
}
 
开发者ID:akarnokd,项目名称:RxJava2Jdk8Interop,代码行数:19,代码来源:FlowableInteropTest.java

示例3: mapOptionalAsyncFusedConditional

import io.reactivex.processors.UnicastProcessor; //导入方法依赖的package包/类
@Test
public void mapOptionalAsyncFusedConditional() {
    TestSubscriber<Integer> ts = TestHelper.fusedSubscriber(QueueSubscription.ANY);

    UnicastProcessor<Integer> up = UnicastProcessor.create();
    TestHelper.emit(up, 1, 2, 3, 4, 5);

    up
    .compose(FlowableInterop.mapOptional(v -> {
        if (v % 2 == 0) {
            return Optional.of(-v);
        }
        return Optional.empty();
    }))
    .filter(Functions.alwaysTrue())
    .subscribeWith(ts)
    .assertOf(TestHelper.assertFusedSubscriber(QueueSubscription.ASYNC))
    .assertResult(-2, -4);
}
 
开发者ID:akarnokd,项目名称:RxJava2Jdk8Interop,代码行数:20,代码来源:FlowableInteropTest.java

示例4: tryOnNext

import io.reactivex.processors.UnicastProcessor; //导入方法依赖的package包/类
@Override
public boolean tryOnNext(T t) {
    UnicastProcessor<T> w = window;
    if (w == null) {
        // ignore additional items after last window is completed
        if (cancelled.get()) {
            return true;
        }
        // emit next window
        w = UnicastProcessor.<T>create(bufferSize, this);
        window = w;
        getAndIncrement();
        if (mode == Mode.BEFORE) {
            requestedWindows.getAndDecrement();
        }
        actual.onNext(w);
    }

    boolean b;

    try {
        // negate predicate for windowWhile
        b = predicate.test(t) ^ mode == Mode.BEFORE;
    } catch (Throwable ex) {
        Exceptions.throwIfFatal(ex);
        s.cancel();
        actual.onError(ex);
        w.onError(ex);
        window = null;
        return true;
    }

    if (b) {
        // element goes into current window
        if (mode == Mode.AFTER) {
            w.onNext(t);
        }
        // finish current window
        w.onComplete();
        // element goes into the next requested window
        if (mode == Mode.BEFORE) {
            w = UnicastProcessor.<T>create(bufferSize, this);
            window = w;
            w.onNext(t);
            // add window to drain queue
            pending.set(w);
            // try emitting right away
            drain();
        } else {
            // new window emitted on next upstream item
            window = null;
        }
    } else {
        w.onNext(t);
    }
    return b;
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:58,代码来源:FlowableWindowPredicate.java

示例5: asyncFused

import io.reactivex.processors.UnicastProcessor; //导入方法依赖的package包/类
@Test
public void asyncFused() {
    UnicastProcessor<Integer> up = UnicastProcessor.create();
    MulticastProcessor<Integer> mp = MulticastProcessor.create(4);

    up.subscribe(mp);

    TestSubscriber<Integer> ts = mp.test();

    for (int i = 0; i < 10; i++) {
        up.onNext(i);
    }

    assertFalse(mp.offer(10));

    up.onComplete();

    ts.assertResult(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:20,代码来源:MulticastProcessorTest.java


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