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

Adds Task.do #128

Merged
merged 3 commits into from Jul 10, 2017
Jump to file or symbol
Failed to load files and symbols.
+7 −12
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

(fix base) Replaces Task.do implementation

Task.do now uses Task's Monad interface
  • Loading branch information...
framp committed Jun 21, 2017
commit a605c9adae45cc35e2866ff9f5e170c52bbc1fa5
@@ -14,24 +14,19 @@ const Task = require('./_task');
* type: |
* forall v, e: (GeneratorInstance [Task e v Any]) => Any => Task e [v] Any
*/
const runGenerator = (generator, value) => (resolver) => {
const nextGeneratorValue = (generator) => (value) => {
const { value: task, done } = generator.next(value);
task.run().listen({
onCancelled: resolver.cancel,
onResolved: (result) =>
!done ? runGenerator(generator, result)(resolver)
: resolver.resolve(result),
onRejected: resolver.reject
});
};
return !done ? task.chain(nextGeneratorValue(generator))
/* else */ : task;
}
/*~
* stability: experimental
* type: |
* forall v, e: (Generator [Task e v Any]) => Task e [v] Any
*/
const taskDo = generator =>
new Task((resolver) =>
runGenerator(generator())(resolver));
const taskDo = (generator) =>
new Task((resolver) => resolver.resolve(generator()))
.chain((generator) => nextGeneratorValue(generator)());
module.exports = taskDo;
ProTip! Use n and p to navigate between commits in a pull request.