package cn.bunny.demo5;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;

@Slf4j
public class TestNettyFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        NioEventLoopGroup group = new NioEventLoopGroup();
        EventLoop eventLoop = group.next();

        Future<Integer> future = eventLoop.submit(() -> {
            Thread.sleep(1000);
            return 70;
        });

        // 主线程通过 future 来获取结果
        log.debug("主线程等待结果");
        future.get();
        log.debug("结果是：{}", future.get());
    }
}
