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

Fixes async task from node error #216

Merged
merged 1 commit into from Jan 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/base/source/conversions/nodeback-to-task.js
Expand Up @@ -22,7 +22,7 @@ const { task } = require('folktale/concurrency/task');

const nodebackToTask = fn => (...args) => (
task(r =>
fn(...args, (err, data) => err ? r.reject(err) : r.resolve(data))
fn(...args, (err, data) => r.isCancelled ? undefined : err ? r.reject(err) : r.resolve(data))
cdoublev marked this conversation as resolved.
Show resolved Hide resolved
)
);

Expand Down
10 changes: 10 additions & 0 deletions test/source/specs/base/concurrency/task.js
Expand Up @@ -7,6 +7,7 @@
//
//----------------------------------------------------------------------

const assert = require('assert');
const { property } = require('jsverify');
const env = require('../environment');

Expand Down Expand Up @@ -574,5 +575,14 @@ describe('Data.Task', () => {
const task = convertedFn('test');
await task.run().promise().catch(e => $ASSERT(e === error));
});

it('Should allow rejecting more than once', async () => {
cdoublev marked this conversation as resolved.
Show resolved Hide resolved
const error = 'failed';
const fn = (str, cb) => setTimeout(() => cb(error, ''), 0);
const convertedFn = Task.fromNodeback(fn);
const task1 = convertedFn('test');
const task2 = convertedFn('test');
assert.doesNotThrow(async () => await task1.and(task2).run().promise());
});
});
});