From ecee2902492a88fe0c704c0219655cb77bd2da26 Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Tue, 22 Aug 2023 21:00:26 +0200 Subject: [PATCH] Use getFirstOrNull method Signed-off-by: Sergey Kuznetsov --- .../redisson/RedissonPermitExpirableSemaphore.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java index d40321d6f..78de34a80 100644 --- a/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java +++ b/redisson/src/main/java/org/redisson/RedissonPermitExpirableSemaphore.java @@ -74,7 +74,7 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen @Override public RFuture acquireAsync(long leaseTime, TimeUnit timeUnit) { CompletionStage future = acquireAsync(1, leaseTime, timeUnit) - .thenApply(f -> f.get(0)); + .thenApply(RedissonPermitExpirableSemaphore::getFirstOrNull); return new CompletableFutureWrapper<>(future); } @@ -112,11 +112,12 @@ public class RedissonPermitExpirableSemaphore extends RedissonExpirable implemen } // return get(acquireAsync(permits, ttl, timeUnit)); } - + + @Override public RFuture acquireAsync() { - RFuture> ids = acquireAsync(1, -1, TimeUnit.MILLISECONDS); - CompletionStage f = ids.thenApply(r -> r.get(0)); - return new CompletableFutureWrapper<>(f); + CompletionStage future = acquireAsync(1) + .thenApply(RedissonPermitExpirableSemaphore::getFirstOrNull); + return new CompletableFutureWrapper<>(future); } @Override