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


Java UnicastProcessor类代码示例

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


UnicastProcessor类属于io.reactivex.processors包,在下文中一共展示了UnicastProcessor类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: WindowPredicateSubscriber

import io.reactivex.processors.UnicastProcessor; //导入依赖的package包/类
WindowPredicateSubscriber(Subscriber<? super Flowable<T>> actual,
        Predicate<? super T> predicate, Mode mode,
        int bufferSize) {
    super(1);
    this.actual = actual;
    this.predicate = predicate;
    this.mode = mode;
    this.bufferSize = bufferSize;
    // In Mode.BEFORE windows are opened earlier and added to the 1-element drain "queue"
    if (mode == Mode.BEFORE) {
        requestedWindows = new AtomicLong();
        pending = new AtomicReference<UnicastProcessor<T>>();
    } else {
        requestedWindows = null;
        pending = null;
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:18,代码来源:FlowableWindowPredicate.java

示例5: runAsyncProcessor

import io.reactivex.processors.UnicastProcessor; //导入依赖的package包/类
@Test
public void runAsyncProcessor() {
    AsyncFlowable.runAsync(Schedulers.single(),
        UnicastProcessor.<Object>create(),
    new BiConsumer<Subscriber<Object>, Disposable>() {
        @Override
        public void accept(Subscriber<? super Object> s, Disposable d) throws Exception {
            s.onNext(1);
            s.onNext(2);
            s.onNext(3);
            Thread.sleep(200);
            s.onNext(4);
            s.onNext(5);
            s.onComplete();
        }
    })
    .test()
    .awaitDone(5, TimeUnit.SECONDS)
    .assertResult(1, 2, 3, 4, 5);
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:21,代码来源:AsyncFlowableTest.java

示例6: drain

import io.reactivex.processors.UnicastProcessor; //导入依赖的package包/类
private void drain() {
    if (requestedWindows.get() <= 0) {
        return;
    }
    UnicastProcessor<T> w = pending.getAndSet(null);
    if (w == null) {
        return;
    }
    getAndIncrement();
    requestedWindows.getAndDecrement();
    actual.onNext(w);
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:13,代码来源:FlowableWindowPredicate.java

示例7: 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

示例8: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。