Skip to content

Parallel transformations are run twice when one of the Futures resolves the other synchronously #367

@Avaq

Description

@Avaq

First discovered in fluture-js/fluture-hooks#6, this is one of several thinkable issues that arise once control over the resolution of a Future is taken outside of the Future constructor, for example:

let exportedRes;

// We're defeating Fluture's design and exfiltrating the res function:
const m1 = Future ((rej, res) => {
  exportedRes = res;
});

// Then we create another Future which forces the resolution of the former:
const m2 = Future ((rej, res) => {
  res (42);
  exportedRes (42);
});

// Now when we (re)combine these two Futures with Fluture, Fluture
// is going to run the effect of `both` (or whatever combinator was
// used) twice: once as a result of m2 starting a parallel process,
// and once more for m1 resolving as a result of that parallel process.
both (m1) (m2)

The example above is very similar to what fluture-hooks does to achieve its parallel applicative instance. Arguably, this is not a bug, because the user is abusing Fluture: they're manually combining m1 and m2 outside of Fluture's API for combining Futures. However, since it's possible to achieve this at all; I still want to record it as a bug and think about how Fluture should behave under these scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions