reactor.core.publisher.Operators.toConditionalSubscriber()方法的使用及代码示例

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

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

Operators.toConditionalSubscriber介绍

[英]If the actual CoreSubscriber is not Fuseable.ConditionalSubscriber, it will apply an adapter which directly maps all Fuseable.ConditionalSubscriber#tryOnNext(T) to CoreSubscriber#onNext(T)and always returns true as the result
[中]如果实际的CoreSubscriber不可熔合。ConditionalSubscriber,它将应用一个适配器,该适配器直接映射所有可熔合的。ConditionalSubscriber#tryOnNext(T)到CoreSubscriber#onNext(T),并始终返回true作为结果

代码示例

代码示例来源:origin: reactor/reactor-core

@Test
  public void convertConditionalToConditionalShouldReturnTheSameInstance() {
    Fuseable.ConditionalSubscriber original = Mockito.mock(Fuseable.ConditionalSubscriber.class);

    Assertions.assertThat(Operators.toConditionalSubscriber(original))
         .isEqualTo(original);
  }
}

代码示例来源:origin: reactor/reactor-core

@Override
public void subscribe(CoreSubscriber<? super T> actual) {
  if (state == STATE_INIT && STATE.compareAndSet(this, STATE_INIT, STATE_SUBSCRIBED_ONCE)) {
    if (first == null && done) {
      if (throwable != null) {
        Operators.error(actual, throwable);
      }
      else {
        Operators.complete(actual);
      }
      return;
    }
    INNER.lazySet(this, Operators.toConditionalSubscriber(actual));
    actual.onSubscribe(this);
  }
  else {
    Operators.error(actual, new IllegalStateException("FluxSwitchOnFirst allows only one Subscriber"));
  }
}

代码示例来源:origin: reactor/reactor-core

@Test
public void convertNonConditionalToConditionalSubscriberTest() {
  Object elementToSend = new Object();
  ArrayList<Object> captured = new ArrayList<>();
  BaseSubscriber<Object> actual = new BaseSubscriber<Object>() {
    @Override
    protected void hookOnNext(Object value) {
      captured.add(value);
    }
  };
  Fuseable.ConditionalSubscriber<? super Object> conditionalSubscriber =
    Operators.toConditionalSubscriber(actual);
  Assertions.assertThat(conditionalSubscriber).isNotEqualTo(actual);
  Assertions.assertThat(conditionalSubscriber.tryOnNext(elementToSend)).isTrue();
  Assertions.assertThat(captured).containsExactly(elementToSend);
}

代码示例来源:origin: io.projectreactor/reactor-core

@Override
public void subscribe(CoreSubscriber<? super T> actual) {
  if (state == STATE_INIT && STATE.compareAndSet(this, STATE_INIT, STATE_SUBSCRIBED_ONCE)) {
    if (first == null && done) {
      if (throwable != null) {
        Operators.error(actual, throwable);
      }
      else {
        Operators.complete(actual);
      }
      return;
    }
    INNER.lazySet(this, Operators.toConditionalSubscriber(actual));
    actual.onSubscribe(this);
  }
  else {
    Operators.error(actual, new IllegalStateException("FluxSwitchOnFirst allows only one Subscriber"));
  }
}

相关文章