Skip to content

Commit

Permalink
Fixes async task from node error
Browse files Browse the repository at this point in the history
Fixes #215
  • Loading branch information
cdoublev authored and robotlolita committed Jan 13, 2019
1 parent 5d23381 commit 65ec995
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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))
)
);

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 () => {
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());
});
});
});

0 comments on commit 65ec995

Please sign in to comment.