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 a function has More than two params #59

Closed
HoKangInfo opened this issue Apr 26, 2018 · 5 comments
Closed

promisify a function has More than two params #59

HoKangInfo opened this issue Apr 26, 2018 · 5 comments
Assignees
Milestone

Comments

@HoKangInfo
Copy link

HoKangInfo commented Apr 26, 2018

v1.11

promisify a function that callback function has More than two params

e.q.

const { exec } = require('child_process');
const exec_1 =  require('util').promisify(exec);
const exec_2 = require('aigle').promisify(exec);

const cmd = 'ls 1>&2';
exec_1(cmd).then(raw=> console.log('exec 1=>',raw)).catch(e=>console.log('exec 1 error=>',e));
exec_2(cmd).then(raw=> console.log('exec 2=>',raw)).catch(e=>console.log('exec 2 error=>',e));

.result

exec 1 => { stdout: '',  stderr: 'a.file'}
exec 2 => 
@thammin
Copy link
Collaborator

thammin commented Apr 26, 2018

Currently util.promisify handles some non-standard callbacks via the internal symbol as here.

For your case, exec's custom promise was defined under here.
So we can check if there is any custom promise like this.

const { exec } = require('child_process');
const { promisify } = require('util');
if (exec[promisify.custom]) {
  // fallback to use the custom promise
}

There is other custom promises too.
Examples:

  • child_process.exec
  • child_process.execFile
  • dns.lookup
  • dns.lookupService
  • fs.read
  • fs.write

Btw, we need to implement this in Node.js environment only and just skip the checks in browser.

@HoKangInfo
Copy link
Author

Thank for your reply.
I understand child_process.exec is non-standard callback.
Just to discuss need or not support.

@suguru03
Copy link
Owner

@HoKangInfo @thammin Thanks for the issue, it is so helpful!
Yes, let's support it! 😄

we need to implement this in Node.js environment only and just skip the checks in browser.

Sure, we need to handle it. 👍

@suguru03 suguru03 self-assigned this Apr 30, 2018
@suguru03 suguru03 added this to the v1.12 milestone Apr 30, 2018
@suguru03
Copy link
Owner

I published it on v1.12.0-alpha.7.
But I just realized the promisified function doesn't return Aigle instances. I'll think about it more.

@suguru03
Copy link
Owner

suguru03 commented May 7, 2018

I published it on v1.12.0!

@suguru03 suguru03 closed this as completed May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants