-
Notifications
You must be signed in to change notification settings - Fork 29
Closed
Description
Hi!
I stumbled upon your library and it looks very promising! Thanks for the hard work you put into it.
While testing timeouts and cancellations, the behavior I am seeing is not what I would expect though. Here's an example:
public void test() {
return CompletableTask
.supplyAsync(() -> {
try {
Thread.sleep(10_000); // sleep 10s
} catch (InterruptedException e) {
System.out.println("Interrupted");
throw new CompletionException(e);
}
System.out.println("Interrupted? " + (Thread.currentThread().isInterrupted() ? "yes" : "no"));
return "foo";
}, Executors.newCachedThreadPool())
.orTimeout(Duration.ofMillis(200), true)
.join();
}
With such a code, I would expect the Thread.sleep()
to be interrupted after 200ms but it does not seem to be the case ("Interrupted: no" is printed after 10s). Is that the expected behavior? Am I doing something wrong?
Also, I noticed that different executors will provide different results. Using newCachedThreadPool()
will return a result after 200ms while using newSingleThreadExecutor()
or Spring's ThreadPoolTaskExecutor
will return but only after 10s. Again, is that expected?
Thanks!
Metadata
Metadata
Assignees
Labels
No labels