首页 > 其他 > 详细

Reactor系列(二)Flux Mono创建

时间:2019-12-11 13:50:06      阅读:83      评论:0      收藏:0      [点我收藏+]

Flux Mono创建

视频讲解:https://www.bilibili.com/video/av78844777/

技术分享图片

FluxMonoTestCase.java
package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

@Slf4j
public class FluxMonoTestCase extends BaseTestCase {
    @Test
    public void createFlux() throws InterruptedException {
        //整型
        Flux<Integer> integerFlux = Flux.just(1, 2, 3, 4, 5);
        //字符串
        Flux<String> stringFlux = Flux.just("hello", "world");
        List<String> list = Arrays.asList("hello", "world");
        //列表
        Flux<String> stringFlux1 = Flux.fromIterable(list);
        //范围
        Flux<Integer> integerFlux1 = Flux.range(1, 5);
        //时间间隔
        Flux<Long> longFlux = Flux.interval(Duration.ofMillis(1000));
        longFlux.subscribe(System.out::println);

        //Flux 创建
        Flux<String> stringFlux2 = Flux.from(stringFlux1);
        stringFlux2.subscribe(System.out::println);
        Thread.sleep(Long.MAX_VALUE);
    }
}

关注公众号,坚持每天3分钟视频学习

技术分享图片

Reactor系列(二)Flux Mono创建

原文:https://www.cnblogs.com/JavaWeiBianCheng/p/12021925.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!