cyclops.reactive.ReactiveSeq.fromPublisher()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(88)

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

ReactiveSeq.fromPublisher介绍

[英]Construct a ReactiveSeq from an Publisher
[中]从发布者处构造一个ReactiveSeq

代码示例

代码示例来源:origin: aol/cyclops

@Override
default <U, R> ReactiveSeq<R> zip(final BiFunction<? super T, ? super U, ? extends R> zipper, final Publisher<? extends U> other) {
  return zipWithStream(ReactiveSeq.fromPublisher(other), zipper);
}

代码示例来源:origin: aol/cyclops

@Test
public void fromFluxReactiveSeq(){
  assertThat( ReactiveSeq.fromPublisher(Flux.just(1,2,3)).toList(),equalTo(
      Arrays.asList(1,2,3)));
}

代码示例来源:origin: aol/cyclops

@Test
public void flatMapSynchronous(){
  for(int i=0;i<ITERATIONS;i++){
    System.out.println("***************************Iteration " + i);
    System.out.println("***************************Iteration " + i);
    System.out.println("***************************Iteration " + i);
    System.out.println("***************************Iteration " + i);
    System.out.println("***************************Iteration " + i);
    System.out.println("***************************Iteration " + i);
    System.out.println("***************************Iteration " + i);
    System.out.println("***************************Iteration " + i);
    assertThat(ReactiveSeq.fromPublisher(of(1)
            .flatMap(in -> of(1, 2, 3)))
            .toList(),
        equalTo(Arrays.asList(1, 2, 3)));
  }
}
@Test

代码示例来源:origin: aol/cyclops

@Test
public void mergePAsyncSynchronous2(){
  for(int k=0;k<ITERATIONS;k++) {
    System.out.println("****************************NEXT ITERATION "+ k);
    System.out.println("****************************NEXT ITERATION "+ k);
    System.out.println("****************************NEXT ITERATION "+ k);
    System.out.println("****************************NEXT ITERATION "+ k+ "**************************");
    List<Integer> res =  ReactiveSeq.fromPublisher(Spouts.mergeLatest(nextAsync(),nextAsync(),nextAsync()))
        .toList();
    System.out.println("Result is " + res);
    assertThat(res.size(), equalTo(Arrays.asList(1, 2, 1, 2, 1, 2).size()));
    assertThat(res, hasItems(1,2));
    int one = 0;
    int two = 0;
    for(Integer next : res){
      if(next==1){
        one++;
      }
      if(next==2){
        two++;
      }
    }
    assertThat(one,equalTo(3));
    assertThat(two,equalTo(3));
  }
}
private Publisher<Integer> nextAsync() {

代码示例来源:origin: aol/cyclops

@Test
public void flatMapPSynchronous(){
  for(int i=0;i<ITERATIONS;i++){
    System.out.println("Iteration " + i);
    assertThat(ReactiveSeq.fromPublisher(of(1)
            .mergeMap(in -> of(1, 2, 3)))
            .toList(),
        equalTo(Arrays.asList(1, 2, 3)));
  }
}
@Test

代码示例来源:origin: aol/cyclops

protected <U> ReactiveSeq<U> flux(U... array){
  return ReactiveSeq.fromPublisher(Flux.just(array).subscribeOn(Schedulers.fromExecutor(ForkJoinPool.commonPool())));
}
@Test

代码示例来源:origin: aol/cyclops

@Test
  public void ambSemigroupTest(){

    System.out.println(ReactiveSeq.fromPublisher(
  Semigroups.<Integer>amb()
    .apply(Spouts.of(100,200,300),nextAsyncRS())).collect(Collectors.toList()));
/**
    ReactiveSeq.fromPublisher(Flux.amb(nextAsync(),nextAsyncRS()))
        .forEach(System.out::println);
**/
 /**
    assertThat(SemigroupK.<Integer>amb()
        .applyHKT(Spouts.of(100,200,300),nextAsyncRS()).listX(),equalTo(ListX.of(100,200,300)));
    assertThat(SemigroupK.<Integer>amb()
        .applyHKT(nextAsyncRS(),Spouts.of(100,200,300)).listX(),equalTo(ListX.of(100,200,300)));
**/
  }
  AtomicInteger start= new AtomicInteger(0);

代码示例来源:origin: aol/cyclops

protected <U> ReactiveSeq<U> flux(U... array){
  return ReactiveSeq.fromPublisher(Flux.just(array).subscribeOn(Schedulers.fromExecutor(ForkJoinPool.commonPool())));
}
@Test

代码示例来源:origin: com.oath.cyclops/cyclops

@Override
default <U, R> ReactiveSeq<R> zip(final BiFunction<? super T, ? super U, ? extends R> zipper, final Publisher<? extends U> other) {
  return zipWithStream(ReactiveSeq.fromPublisher(other), zipper);
}

相关文章

微信公众号

最新文章

更多

ReactiveSeq类方法