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

fromPromise executes the promise immediately #10

@foxdonut

Description

@foxdonut

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions