-
Notifications
You must be signed in to change notification settings - Fork 102
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
Allow fn passed to Async.fromNode to be partially applied #478
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
Comment on lines
+51
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evilsoft I know there is the issue with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, we should be good with this. |
||
fn.apply(ctx, | ||
args.concat( | ||
(err, data) => err ? reject(err) : resolve(data) | ||
) | ||
) | ||
}) | ||
} | ||
} | ||
|
||
function fromPromise(fn) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per your documentation and our discussions their is a chance that the given function has a length of 0. Would this be a case to return an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding at this point is that if the function has a length of 0 then the safest thing to do is assume that it isn't being partially applied, and apply all of the parameters as per usual. This will mean that any code that currently passes a
compose
d or...args
orargument
function will continue to work in exactly the same way as it does today.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, sounds good to me