forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up sync calls; add close connection
Signed-off-by: Andrew Carbonetto <[email protected]>
- Loading branch information
1 parent
537d538
commit 2f81317
Showing
10 changed files
with
47 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
package babushka.api; | ||
|
||
import java.util.concurrent.Future; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class Awaiter { | ||
private static final long DEFAULT_TIMEOUT_MILLISECONDS = 1000; | ||
|
||
/** Get the future result with default timeout. */ | ||
public static <T> T await(Future<T> future) { | ||
public static <T> T await(CompletableFuture<T> future) { | ||
return await(future, DEFAULT_TIMEOUT_MILLISECONDS); | ||
} | ||
|
||
/** Get the future result with given timeout in ms. */ | ||
public static <T> T await(Future<T> future, long timeout) { | ||
public static <T> T await(CompletableFuture<T> future, long timeout) { | ||
try { | ||
return future.get(timeout, TimeUnit.MILLISECONDS); | ||
} catch (Exception ignored) { | ||
return null; | ||
} catch (ExecutionException | InterruptedException | TimeoutException e) { | ||
// TODO: handle exceptions: | ||
// InterruptedException: should shutdown the client service | ||
// TimeoutException: should be propagated with an error message thrown | ||
// ExecutionException: throw runtime exception | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
java/client/src/test/java/babushka/connectors/SocketConnectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package babushka.connectors; | ||
|
||
public class SocketConnectionTest {} |