Comments (5)
Hello,
I haven't tested your code, but the issue seems to be related to poorly documented Promise.dependent()
operator rather than to Promises.all()
behavior. You should either use Promise.dependent(PromiseOrigin.ALL)
or add true
as a last parameter to thenAccept(...)
- i.e. use overloaded form.
So your code should be either:
@Test
public void testWrappedCancelEarly() throws Exception {
ElapsedTime time = new ElapsedTime();
Promise<Void> promise0 = CompletableTask.runAsync(taskOf(time, 2000, 0), Executors.getDefaultExecutor());
Promise<Void> promise1 = CompletableTask.runAsync(taskOf(time, 2000, 1), Executors.getDefaultExecutor());
Promise<Void> promise2 = CompletableTask.runAsync(taskOf(time, 2000, 2), Executors.getDefaultExecutor());
Promise<Void> dependentPromise0 = promise0.dependent(PromiseOrigin.ALL).thenAccept(secondStep(time, 1000, 0)); // Use PromiseOrigin.ALL
Promise<Void> dependentPromise1 = promise1.dependent(PromiseOrigin.ALL).thenAccept(secondStep(time, 1000, 1)); // Use PromiseOrigin.ALL
Promise<Void> dependentPromise2 = promise2.dependent(PromiseOrigin.ALL).thenAccept(secondStep(time, 1000, 2)); // Use PromiseOrigin.ALL
Promise<List<Void>> combinedPromise = Promises.all(dependentPromise0, dependentPromise1, ...)
...
}
...or...
@Test
public void testWrappedCancelEarly() throws Exception {
ElapsedTime time = new ElapsedTime();
Promise<Void> promise0 = CompletableTask.runAsync(taskOf(time, 2000, 0), Executors.getDefaultExecutor());
Promise<Void> promise1 = CompletableTask.runAsync(taskOf(time, 2000, 1), Executors.getDefaultExecutor());
Promise<Void> promise2 = CompletableTask.runAsync(taskOf(time, 2000, 2), Executors.getDefaultExecutor());
Promise<Void> dependentPromise0 = promise0.dependent().thenAccept(secondStep(time, 1000, 0), true); // Overloaded operator with true
Promise<Void> dependentPromise1 = promise1.dependent().thenAccept(secondStep(time, 1000, 1), true); // Overloaded operator with true
Promise<Void> dependentPromise2 = promise2.dependent().thenAccept(secondStep(time, 1000, 2), true); // Overloaded operator with true
Promise<List<Void>> combinedPromise = Promises.all(dependentPromise0, dependentPromise1, ...)
...
}
from tascalate-concurrent.
Thank you for the quick response. The supposed solutions work fine.
from tascalate-concurrent.
Hi there,
the tests now work very well but unfortunately a real life example does not work. Please have a look onto another test method:
reallife.txt
The sleep(30000);
at the end keeps the programm running. So you can see (on System.out) the threads are still running in background allthough the combinedPromise
has been canceled after 4s. Maybe interrupting the threads does not work as expected?
from tascalate-concurrent.
This is expected while your code inside id -> CompletableTask.runAsync(() -> {})
does not react on interruptions.
Please add the following to preVisitDirectory
and visitFile
:
if (Thread.currentThread().isInterrupted()) {
return FileVisitResult.TERMINATE;
}
from tascalate-concurrent.
Thank you, that does the trick. I supposed that Files#walkFileTree
does those checks. But maybe it is better to add the check outside.
from tascalate-concurrent.
Related Issues (20)
- Issues with Callbacks HOT 11
- OnTimeout not working when computing intensive task HOT 5
- orTime and submit combination HOT 5
- How to wrap a Promise into Promise.retry HOT 5
- Typo in DelayPolicy#withMinDelay HOT 1
- Feature enhancement on cancel HOT 2
- A FutureLocal.java would be nice(like ThreadLocal.java but more) HOT 1
- MultitargetException swallows Exceptions HOT 7
- Include class names in the documentation when highlighting a method
- Unexpected cancellation behavior HOT 6
- Promise.onTimeout does not cancel the async call in original CompletableTask.supplyAsync? HOT 8
- The cancel is not working on the async chain HOT 3
- Wait for Interrupted of CompletableTask.cancel HOT 4
- onTimeout behaviour confusing after 0.8.4 HOT 2
- Optimized Same Executor Runs HOT 1
- Mapped promise can't be interrupted HOT 1
- Exceptions in thenCompose() will not propagate HOT 3
- Promises.all - List type argument HOT 3
- whenCompleteAsync adds the failure exception as a suppressed exception to itself HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tascalate-concurrent.