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

x33g5p2x  于2022-01-24 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(276)

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

Mono.first介绍

[英]Pick the first available result coming from any of the given monos and populate a new Mono.
[中]从任何给定的Mono中选择第一个可用的结果,并填充一个新的Mono。

代码示例

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

/**
 * Emit the first available result from this mono or the other mono.
 *
 * <p>
 * <img class="marble" src="doc-files/marbles/orForMono.svg" alt="">
 *
 * @param other the racing other {@link Mono} to compete with for the result
 *
 * @return a new {@link Mono}
 * @see #first
 */
public final Mono<T> or(Mono<? extends T> other) {
  if (this instanceof MonoFirst) {
    MonoFirst<T> a = (MonoFirst<T>) this;
    Mono<T> result =  a.orAdditionalSource(other);
    if (result != null) {
      return result;
    }
  }
  return first(this, other);
}

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

Mono<Integer> scenario_fastestSource() {
  return Mono.first(Mono.delay(Duration.ofSeconds(4))
             .map(s -> 1),
      Mono.delay(Duration.ofSeconds(3))
        .map(s -> 2));
}

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

@Test(timeout = 5000)
public void someEmptyIterable() {
  Assert.assertNull(Mono.first(Arrays.asList(Mono.empty(),
      Mono.delay(Duration.ofMillis(250))))
             .block());
}

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

@Test(timeout = 5000)
public void someEmpty() {
  Assert.assertNull(Mono.first(Mono.empty(), Mono.delay(Duration.ofMillis(250)))
             .block());
}

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

@Test//(timeout = 5000)
public void all2NonEmptyIterable() {
  Assert.assertEquals(Integer.MIN_VALUE,
      Mono.first(Mono.delay(Duration.ofMillis(150))
              .map(i -> Integer.MIN_VALUE), Mono.delay(Duration.ofMillis(250)))
        .block());
}

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

@Test//(timeout = 5000)
public void all2NonEmpty() {
  Assert.assertEquals(Integer.MIN_VALUE,
      Mono.first(Mono.delay(Duration.ofMillis(150))
              .map(i -> Integer.MIN_VALUE), Mono.delay(Duration.ofMillis(250)))
        .block());
}

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

@Test(timeout = 5000)
public void allEmptyIterable() {
  Assert.assertNull(Mono.first(Arrays.asList(Mono.empty(),
      Mono.delay(Duration.ofMillis(250))
        .ignoreElement()))
             .block());
}

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

@Test(timeout = 5000)
public void allEmpty() {
  Assert.assertNull(Mono.first(Mono.empty(),
      Mono.delay(Duration.ofMillis(250))
        .ignoreElement())
             .block());
}

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

@Test
public void firstMonoJust() {
  MonoProcessor<Integer> mp = MonoProcessor.create();
  StepVerifier.create(Mono.first(Mono.just(1), Mono.just(2))
              .subscribeWith(mp))
        .then(() -> assertThat(mp.isError()).isFalse())
        .then(() -> assertThat(mp.isSuccess()).isTrue())
        .then(() -> assertThat(mp.isTerminated()).isTrue())
        .expectNext(1)
        .verifyComplete();
}

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

@Test
public void pairWiseIterable() {
  Mono<Integer> f = Mono.first(Arrays.asList(Mono.just(1), Mono.just(2)))
             .or(Mono.just(3));
  Assert.assertTrue(f instanceof MonoFirst);
  MonoFirst<Integer> s = (MonoFirst<Integer>) f;
  Assert.assertTrue(s.array != null);
  Assert.assertTrue(s.array.length == 2);
  f.subscribeWith(AssertSubscriber.create())
   .assertValues(1)
   .assertComplete();
}

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

@Test
public void pairWise() {
  Mono<Integer> f = Mono.first(Mono.just(1), Mono.just(2))
             .or(Mono.just(3));
  Assert.assertTrue(f instanceof MonoFirst);
  MonoFirst<Integer> s = (MonoFirst<Integer>) f;
  Assert.assertTrue(s.array != null);
  Assert.assertTrue(s.array.length == 3);
  f.subscribeWith(AssertSubscriber.create())
   .assertValues(1)
   .assertComplete();
}

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

/**
 * Emit the first available result from this mono or the other mono.
 *
 * <p>
 * <img class="marble" src="doc-files/marbles/orForMono.svg" alt="">
 *
 * @param other the racing other {@link Mono} to compete with for the result
 *
 * @return a new {@link Mono}
 * @see #first
 */
public final Mono<T> or(Mono<? extends T> other) {
  if (this instanceof MonoFirst) {
    MonoFirst<T> a = (MonoFirst<T>) this;
    Mono<T> result =  a.orAdditionalSource(other);
    if (result != null) {
      return result;
    }
  }
  return first(this, other);
}

代码示例来源:origin: com.aol.cyclops/cyclops-reactor

/**
 * Combines Monos by selecting the first result returned
 *
 * <pre>
 * {@code
 *  MonoKind<Integer> ft = Monos.<Integer>monadPlus()
.plus(MonoKind.widen(Mono.empty()), MonoKind.widen(Mono.just(10)))
.convert(MonoKind::narrowK);
//Mono.empty()
 *
 * }
 * </pre>
 * @return Type class for combining Monos by concatenation
 */
public static <T> MonadPlus<mono> monadPlus(){
  Monoid<MonoKind<T>> m = Monoid.of(MonoKind.<T>widen(Mono.empty()),
      (f,g)-> widen(Mono.first(f.narrow(),g.narrow())));
  Monoid<Higher<mono,T>> m2= (Monoid)m;
  return General.monadPlus(monadZero(),m2);
}
/**

相关文章

Mono类方法