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

fn.name and fn.length? #1

Closed
jprichardson opened this issue Apr 18, 2017 · 3 comments
Closed

fn.name and fn.length? #1

jprichardson opened this issue Apr 18, 2017 · 3 comments

Comments

@jprichardson
Copy link

jprichardson commented Apr 18, 2017

Piggybacking from this comment... jprichardson/node-fs-extra#403 (comment)

Why wouldn't you want to set fn.name and fn.length? Stated another way, why wouldn't you want to take the implementation from https://github.com/paulmillr/micro-promisify/blob/600daee25abc75af3cef8145ef6eb55aafdd2d54/index.js#L11? I'm not saying that implementation is correct, I'm just interested in your reasoning.

@RyanZim
Copy link
Owner

RyanZim commented Apr 18, 2017

OK, perhaps I wasn't clear enough. I do want to set fn.name. I'll be fixing that as soon as I can.


Regarding fn.length: Suppose we have this function:

function foo (a, b, callback) { ... }

We want to universalify it:

const newFoo = universalify.fromCallback(foo)

Now, we can use it like this:

newFoo(1, 2)
.then(..)
.catch(..)

or like this:

newFoo(1, 2, (err, res) => {
  // Do something
})

Note that in the first example, we called newFoo with 2 arguments. In the second example, we called it with 3.

micro-promisify doesn't support calling the transformed functions with callbacks, so it sets fn.length to Math.max(0, fn.length - 1). This logic doesn't apply to universalify, since it's still possible to call the function with a callback.

However, if we keep the old fn.length value, this might be confusing for promise users. Also, should functions passed to fromPromise have their length bumped by 1 or not?

Therefore, I was thinking of just leaving fn.length unset.

@jprichardson
Copy link
Author

Ah, everything makes sense. Got it.

@RyanZim
Copy link
Owner

RyanZim commented Apr 19, 2017

OK, I'll fix name later today, then we can move forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants