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

promisify resolves only single parametar #5

Closed
snovakovic opened this issue Jun 15, 2017 · 1 comment
Closed

promisify resolves only single parametar #5

snovakovic opened this issue Jun 15, 2017 · 1 comment
Assignees
Labels

Comments

@snovakovic
Copy link
Owner

snovakovic commented Jun 15, 2017

const fun = promisify((cb) => cb(undefined, 'res1', 'res2', 'res3'));

fun().then((r1, r2, r3) => {
  // r1 => 'res1'
  // r2 && r3 are undefined
});
@snovakovic
Copy link
Owner Author

snovakovic commented Jun 15, 2017

resolve() can return only single value. To resolve this we could return array when there is multiple parameters.

fun().then(([r1, r2, r3]) => {
  // r1 => 'res1' 
  // r2 => 'res2'
  // r3 => 'res3'
});

That would break code if there is inconsistent callback that sometimes returns one parameter and other time multiple parameter.

For consistency we should always return single parameter or array of parameters. We can default to single parameter as that is most common scenario. we can allow additional options that will dictate array of parameters to be always returned (even if single parameter)
promisify(cbFun, { multiArgs: true })

@snovakovic snovakovic self-assigned this Jun 15, 2017
@snovakovic snovakovic added the bug label Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant