diff --git a/src/Async/Async.spec.js b/src/Async/Async.spec.js index 4f963472f..8830622dd 100644 --- a/src/Async/Async.spec.js +++ b/src/Async/Async.spec.js @@ -225,6 +225,21 @@ test('Async fromNode resolution', t => { Async.fromNode(resCPS)(val).fork(rej(val), res(val)) }) +test('Async fromNode partially applied', t => { + t.plan(2) + + const val = 'super fun' + + const rejCPS = (x, y, cf) => cf(x, y) + const resCPS = (x, y, cf) => cf(null, x, y) + + const rej = y => x => t.equal(x, y, 'rejects an erred CPS') + const res = y => x => t.equal(x, y, 'resolves a good CPS') + + Async.fromNode(rejCPS)(val)(val).fork(rej(val), res(val)) + Async.fromNode(resCPS)(val)(val).fork(rej(val), res(val)) +}) + test('Async all', t => { const all = bindFunc(Async.all) diff --git a/src/Async/index.js b/src/Async/index.js index d902de6d4..f72bd2a04 100644 --- a/src/Async/index.js +++ b/src/Async/index.js @@ -48,14 +48,22 @@ function fromNode(fn, ctx) { throw new TypeError('Async.fromNode: CPS function required') } - return (...args) => - Async((reject, resolve) => { + const _fn = curry(fn) + + return (...args) => { + + if (args.length < _fn.length - 1) { + return fromNode(_fn(...args), ctx) + } + + return Async((reject, resolve) => { fn.apply(ctx, args.concat( (err, data) => err ? reject(err) : resolve(data) ) ) }) + } } function fromPromise(fn) {