diff --git a/src/main/java/org/redkale/net/client/Client.java b/src/main/java/org/redkale/net/client/Client.java index efd4d4835..b67efd980 100644 --- a/src/main/java/org/redkale/net/client/Client.java +++ b/src/main/java/org/redkale/net/client/Client.java @@ -80,7 +80,7 @@ public abstract class Client, R extends ClientR protected Supplier closeRequestSupplier; //创建连接后进行的登录鉴权操作 - protected Function, CompletableFuture> authenticate; + protected Function> authenticate; protected Client(String name, AsyncGroup group, ClientAddress address) { this(name, group, true, address, Utility.cpus(), DEFAULT_MAX_PIPELINES, null, null, null); @@ -99,18 +99,18 @@ public abstract class Client, R extends ClientR } protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns, - Function, CompletableFuture> authenticate) { + Function> authenticate) { this(name, group, tcp, address, maxConns, DEFAULT_MAX_PIPELINES, null, null, authenticate); } protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns, - Supplier closeRequestSupplier, Function, CompletableFuture> authenticate) { + Supplier closeRequestSupplier, Function> authenticate) { this(name, group, tcp, address, maxConns, DEFAULT_MAX_PIPELINES, null, closeRequestSupplier, authenticate); } @SuppressWarnings("OverridableMethodCallInConstructor") protected Client(String name, AsyncGroup group, boolean tcp, ClientAddress address, int maxConns, - int maxPipelines, Supplier pingRequestSupplier, Supplier closeRequestSupplier, Function, CompletableFuture> authenticate) { + int maxPipelines, Supplier pingRequestSupplier, Supplier closeRequestSupplier, Function> authenticate) { if (maxPipelines < 1) { throw new IllegalArgumentException("maxPipelines must bigger 0"); } @@ -277,7 +277,10 @@ public abstract class Client, R extends ClientR } else { future = future.thenApply(conn -> (C) conn.readChannel()); } - return (authenticate == null ? future : authenticate.apply(future)).thenApply(c -> { + if (authenticate != null) { + future = future.thenCompose(authenticate); + } + return future.thenApply(c -> { c.setAuthenticated(true); this.connArray[index] = c; CompletableFuture f;