Execute the timeout to release the lock correctly #1260
Replies: 2 comments 2 replies
-
Since |
Beta Was this translation helpful? Give feedback.
1 reply
-
I did a test: @Test
public void testUniLockTimeout() throws InterruptedException {
println("start");
Uni.createFrom().voidItem().flatMap(r ->
getLock()
.flatMap(lock -> doSomethingUni(7))
.eventually(this::releaseLock)
).ifNoItem().after(Duration.ofSeconds(3)).fail()
.onFailure().invoke(Throwable::printStackTrace)
.onFailure().recoverWithNull()
.invoke(v -> println("done")).await().indefinitely();
println("stopping");
Thread.sleep(10_000);
println("stopped");
}
private Uni<String> getLock() {
return Uni.createFrom().item("test-lock");
}
private Uni<Void> doSomethingUni(long waitSecond) {
return Uni.createFrom().voidItem().onItem().delayIt().by(Duration.ofSeconds(waitSecond));
}
private void releaseLock() {
println("releaseLock");
}
public static void println(String msg) {
String dataStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
System.out.println(String.format("%s[INFO]-[%s]-[%s]: %s", dataStr, Thread.currentThread().getName(), UnitTest.class.getName(), msg));
}
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here is a code example that simplifies the usage scenario,
How to correctly release the lock after the execution of getLock() and before the execution of releaseLock() has timed out?
Can you help me to write a correct sample code?
Beta Was this translation helpful? Give feedback.
All reactions