Skip to content

Comparison of Future Implementations

Aldwin Vlasblom edited this page Aug 5, 2016 · 38 revisions

Overview

Feature Fluture data.task Ramda Fantasy
Resource disposal βœ… βœ… ❌
Cancellation ❌ πŸ”œ ❌ πŸ”œ ❌
Nice errors βœ… ❌ ❌
Async utilities βœ… βœ… ❌
Throw safety ❌ ❌ βœ…
High performance βœ… βœ… ❌

Features

Resource disposal

Data.task can be constructed with an extra parameter, which expects a function. The function is passed down the chain and exposed as cleanup on the Task instances. Fluture has hook(acquire, cleanup, consume) for managing resources.

Cancellation

Fluture is expirimenting with cancellation. Data.Task is being reworked from the ground up to include cancellation. More information in this issue comment: https://github.com/folktale/data.task/issues/35#issuecomment-220660291

Nice errors

Neither data.task nor Ramda Fantasy perform any kind of type-checking on arguments passed. This often leads to very difficult to understand error messages. Fluture was created to lift that pain:

> Task.of('world').chain(thing => `Hello ${thing}!`).fork(console.error, console.log)
TypeError: f(...).fork is not a function
    at data.task/lib/task.js:117:19
    at data.task/lib/task.js:58:12
    at Task.fork (data.task/lib/task.js:114:12)

> RamdaFuture.of('world').chain(thing => `Hello ${thing}!`).fork(console.error, console.log)
[TypeError: f(...).fork is not a function]

> Fluture.of('world').chain(thing => `Hello ${thing}!`).fork(console.error, console.log)
TypeError: Future#chain expects the function its given to return a Future
  Actual: "Hello world!"
  From calling: thing => `Hello ${thing}!`
  With: "world"
    at check$chain$f (fluture/fluture.js:103:29)
    at Future$chain$res (fluture/fluture.js:229:9)
    at Object.Future$of$fork [as _f] (fluture/fluture.js:214:7)
    at Object.Future$chain$fork [as _f] (fluture/fluture.js:227:13)
    at Object.Future$fork [as fork] (fluture/fluture.js:220:10)

Async utilities

Ramda Fantasy only has Future.cache(). Data.task can be installed with control.async to gain async control utilities. Fluture comes bundled with async control utilities.

Throw safety

Ramda Fantasy prevents thrown errors from ever breaking out. When an error is thrown within one of the functions called by Ramda Fantasy, it ends up in the rejection branch of the Future. This is arguably not a good thing, as documented by this section on error handling.

Performance

The results from this benchmark show a big difference between the performance of Fluture and data.task against Ramda Fantasy:

Fluture x 1,503,508 ops/sec Β±1.18% (91 runs sampled)
data.task x 1,397,057 ops/sec Β±0.80% (91 runs sampled)
Ramda Fantasy x 354,438 ops/sec Β±0.67% (87 runs sampled)

Note that these results will vary significantly between systems and even execution context. They should be taken with a grain of salt. Though in my experience, Fluture comes out fastest however I test it (which was one of the goals for Fluture).

Clone this wiki locally