Giter Club home page Giter Club logo

Comments (7)

vietj avatar vietj commented on May 24, 2024 1

the transform javadoc says: When this future (the one on which transform is called) completes, the mapper will be called with the async result and this mapper returns another future object.

It is possible to extrapolate that join returns a composite future that when it is a success is resolved with the composite future. However as soon as you call transform on this future, then the contract of transform applies.

It is specified that the mapper receives an asynchronous result and not the current future. It turns out it was practical to pass the current future in the initial implementation but this can create leak since the transform operation needs to keep a reference onto the future that created it.

Therefore if the result of join is a success then the mapper of transform is called with an asynchronous result for which the composite future can be obtained with the result of this async result, e.g transform(ar -> { ... ar.result() <- CompositeFuture ... })

from vert.x.

tsegismont avatar tsegismont commented on May 24, 2024

cc @vietj

from vert.x.

vietj avatar vietj commented on May 24, 2024

thanks

from vert.x.

vietj avatar vietj commented on May 24, 2024

@Fyro-Ing I see what you mean but this actually seems to be an abuse of the API, if you want to use the composite future. Simply keep a reference on it like

  @Test
  public void join() {
    waitFor(1);

    final Future<String> f1 = Future.failedFuture(new RuntimeException());
    final Future<String> f2 = Future.failedFuture(new RuntimeException());

    CompositeFuture cf = Future.join(f1, f2);
    cf
      .transform(ar -> {
        // Use CF
        return (CompositeFuture) ar;
      })
      .onComplete(ar -> {
        complete();
      });

    await();
  }

from vert.x.

Fyro-Ing avatar Fyro-Ing commented on May 24, 2024

I suppose that sample as error with ar cast vs cf

This is a breaking change, because transform use previous result, and now, this is not the case.
And now, we need a reference and can't use fluent API directly :/

from vert.x.

vietj avatar vietj commented on May 24, 2024

from vert.x.

Fyro-Ing avatar Fyro-Ing commented on May 24, 2024

I'm not sure how to understand your response, but ar (result from #join) is not a CompositeFuture now, this is a breaking change, from method contract ^^

from vert.x.

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.