New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert between Promises and Futures #98

robotlolita opened this Issue Mar 22, 2017 · 0 comments



robotlolita commented Mar 22, 2017

Promises and Futures are pretty similar, with two major exceptions: Futures have a case for "the computation was cancelled", and they allow you to have futures of futures. Other than that, they're pretty much the same, so it makes sense to be able to convert between them easily.

This means we'd have two basic functions:

promiseToFuture :: (Promise a b) => Future a b
futureToPromise :: (Future a b) => Promise a b

Due to the limitation of promises, the following design decisions should be considered:

  • When converting a Future to a Promise, a Cancellation becomes an errored promise with a special Cancellation object. This object should be available to the user so they can check if a Promise contains a cancellation error.

Where does this go?

In the data/conversions module, as both promiseToFuture and futureToPromise.
In the data/future module, as both toPromise (an instance method), and fromPromise (a module-level function).

Refer to existing data/conversions modules, and the from* and to* functions in data/maybe and data/either to see more or less how this is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment