Skip to content
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

Task.fromNodeBack is not handling cancellation #215

Closed
cdoublev opened this issue Jan 10, 2019 · 2 comments
Closed

Task.fromNodeBack is not handling cancellation #215

cdoublev opened this issue Jan 10, 2019 · 2 comments

Comments

@cdoublev
Copy link
Contributor

All of the Folktale task primitives should be dealing with cancellation.

Task.fromNodeBack currently doesn't prevent resolving|rejecting when the task is cancelled.

Steps to reproduce

Given:

const Task = require('folktale/concurrency/task')

const delay = Task.fromNodeback((result, error, cb) =>
    setTimeout(() => cb(error ? result : null, result)), 0)

This works:

Task.waitAll([delay(1, false), delay(2, true)])
   .orElse(e => Task.rejected(console.log('Error: ', e)))
   .run() // => Error 2

And this don't:

Task.waitAll([delay(1, false), delay(2, true), delay(3, true)])
   .orElse(e => Task.rejected(console.log('Error: ', e)))
   .run() // => Error 2
  // throw new Error('Only pending deferreds can be ' + description + ', this deferred is already ' + description + '.');

Expected behaviour

Last example shouldn't throw an error (Task.fromNodeback should check if task is already cancelled).

Observed behaviour

The error Only pending deferreds can be ' + description + ', this deferred is already ' + description + '.' is thrown.

Environment

  • OS: Vagrant Debian Box
  • JavaScript VM: node v11.6.0
  • Folktale version: 2.3.1

Additional information

Related issue (comment): #153 (comment)
Related file: https://github.com/origamitower/folktale/blob/master/packages/base/source/conversions/nodeback-to-task.js#L25

@robotlolita
Copy link
Member

@cdoublev can you install the beta release and check if it works for you?

$ npm install folktale@next

@cdoublev
Copy link
Contributor Author

Yes, my own (rejection) tests stay green (without yelling about uncaught errors) after updating with @next and reverting all waitAll or and() usages from .apply(). Thank you for fixing/completing my tests. It perfectly answers my question asked in this comment. 👍

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

No branches or pull requests

2 participants