Giter Club home page Giter Club logo

Comments (5)

vsilaev avatar vsilaev commented on May 27, 2024

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.

skidiver avatar skidiver commented on May 27, 2024

Thank you for the quick response. The supposed solutions work fine.

from tascalate-concurrent.

skidiver avatar skidiver commented on May 27, 2024

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.

vsilaev avatar vsilaev commented on May 27, 2024

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.

skidiver avatar skidiver commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.