Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

fromPromise executes the promise immediately #10

Open
foxdonut opened this issue Nov 8, 2015 · 0 comments
Open

fromPromise executes the promise immediately #10

foxdonut opened this issue Nov 8, 2015 · 0 comments

Comments

@foxdonut
Copy link

foxdonut commented Nov 8, 2015

Hi there! Thank you for this awesome library!

I've been exploring control.async and data.task as a way of encapsulating promises into tasks so that promises are not executed until I call fork(..). I find this concept very useful, much like the use of IO to encapsulate code that causes side effects.

Trying out some simple examples, it seems to me that fromPromise executes the promise immediately. This is not fromPromise's fault, but rather that new Promise(..) is not lazy; it does not wait until the call to then before executing the code.

One way around this might be to add something along the lines of a fromPromiseFn function:

function fromPromiseFn(promiseFn, ...args) {
  return new Future(function(reject, resolve) {
    promiseFn(...args).then(resolve, reject);
  });
};

Then, instead of using fromPromise(readFile(filename)), you'd use fromPromiseFn(readFile, filename) to defer the creation of the Promise until fork(..) gets called.

What do you think?

Thanks again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant