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

Implement Task.do() to integrate Tasks with JS syntax #111

Closed
robotlolita opened this Issue Apr 2, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@robotlolita
Member

robotlolita commented Apr 2, 2017

Folktale should add a Task.do(generator) function that allows using generators to integrate Task with JavaScript's syntax, like async/await does for promises. In essence, this would allow one to write:

const readFile = task((resolver) => ...);

const someTask = Task.do(function *() {
  const fileA = yield readFile('a.txt');
  const others = yield Task.parallel([readFile('b.txt'), readFile('c.txt')])
                           .map(xs => xs.join(''));
  return fileA + others;
});

someTask.run().listen({
  onCancelled: () => ...,
  onRejected: (reason) => ...,
  onResolved: (data) => console.log(data)
});

Why?

Since people can convert a Task's execution to a promise, they're already able to use async/await, but that requires buying into the disadvantages promises have. In particular, the fact that promises catch errors automatically, and recursively tries to assimilate any object with a .then method may make programs harder to reason about.

Task.do would provide similar syntactical sugar as async/await does, without the semantic drawbacks of promises.

@robotlolita robotlolita added this to the Post 2.0 milestone Apr 2, 2017

framp added a commit to framp/folktale that referenced this issue Jun 21, 2017

(new base tests) Adds Task.do
`Task.do` accepts a Task-emitting Generator and returns a Task which
will execute all the tasks and pass back the appropriate values to the
Generator.

Fixes origamitower#111

@framp framp referenced this issue Jun 21, 2017

Merged

Adds Task.do #128

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