zoukankan      html  css  js  c++  java
  • FlatMapTest

    package com.test;
    
    import java.time.Duration;
    import java.util.Arrays;
    import lombok.extern.slf4j.Slf4j;
    import org.junit.Test;
    import reactor.core.publisher.Flux;
    
    /**
     * @author: ffzs
     * @Date: 2020/8/7 下午8:18
     */
    
    @Slf4j
    public class FlatMapTest {
    //->a->f->b->f->c->z->d->s
      @Test
      public void flatMap () throws InterruptedException {
        Flux.just("abcd", "ffzs")
            .flatMap(i -> Flux.fromArray(i.split("")).delayElements(Duration.ofMillis(10)))
            .subscribe(i -> System.out.print("->"+i));
        Thread.sleep(100);
      }
    //->a->b->c->d->f->f->z->s
      @Test
      public void flatMapSequential () throws InterruptedException {
        Flux.just("abcd", "ffzs")
            .flatMapSequential(i -> Flux.fromArray(i.split("")).delayElements(Duration.ofMillis(10)))
            .subscribe(i -> System.out.print("->"+i));
        Thread.sleep(1000);
      }
    
     /* @Test
      public void testConcurrencyAndPrefetch() {
        int concurrency = 3;
        int prefetch = 6;
        Flux.range(1, 1)
            //.log()
            .flatMap(i -> Flux.just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
                   .log()
                ,
                concurrency, prefetch)
            .subscribe(i -> System.out.print("->"+i));
      }*/
    //->a->b->c->d->f->f->z->s
        @Test
      public void flatMapIterable () {
        Flux.just("abcd", "ffzs")
            .flatMapIterable(i -> Arrays.asList(i.split("")))
            .subscribe(i -> System.out.print("->"+i));
      }
    //->a->b->c->d->f->f->z->s
      @Test
      public void concatMap () throws InterruptedException {
        Flux.just("abcd", "ffzs")
            .concatMap(i -> Flux.fromArray(i.split("")).delayElements(Duration.ofMillis(10)))
            .subscribe(i -> System.out.print("->"+i));
        Thread.sleep(110);
      }
    //->a->b->c->d->f->f->z->s
     @Test
      public void concatMapIterable () {
        Flux.just("abcd", "ffzs")
            .concatMapIterable(i -> Arrays.asList(i.split("")))
            .subscribe(i -> System.out.print("->"+i));
      }
    }
  • 相关阅读:
    VS2010中添加MVC3和MVC4
    C#--对象转成XML的方法
    Web优化的措施
    Socket的使用(简单测试)
    WCF、WebAPI、WCFREST、WebService之间的区别
    Java和C#(笔记)
    各种窗口最小化快捷键详解
    SASS的安装及使用(前提:安装Ruby)
    查看Linux是32位还是64位
    log4j输出日志到文件
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/13999917.html
Copyright © 2011-2022 走看看