You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It should be possible to promisify the exposed interface, and it will be even easier with the upcoming v1 :)
i don't think we will do this for the v0 branch, but we might consider it on the v1 branch.
Personally I think letting the user promisify the interface is the superior option, as this is easy and limits the scope of this lib. I am open to discussion on this point, though.
The timeline is "when we've checked most or all things off our list" #238 -- my best guess is quite soon after my summer holiday is up. Early to mid september, probably.
A function that takes a callback should never call that callback before yielding to the event loop. Using http or fs or similar usually does this, but for consistency it may slmetimes be necessary to do this explicitly.
It is commonly expected that code like this will always print "b" before "a":
In the above case, if for some reason, net.connect() invoked the callback directly without process.nextTick, the callback would be called immediately, and hence the client variable will not be initialized when the it's accessed by the callback to write to the client!
And for what it's worth, I'd love for promises to be supported out of the box in v1. I personally yield promises in generator functions in most of my projects and I hate having to promisify or thunkify external library functions manually. I love it when libraries provide either a callback or promise interface (if a callback is omitted).
Activity
hypesystem commentedon Jul 20, 2016
It should be possible to promisify the exposed interface, and it will be even easier with the upcoming v1 :)
i don't think we will do this for the v0 branch, but we might consider it on the v1 branch.
Personally I think letting the user promisify the interface is the superior option, as this is easy and limits the scope of this lib. I am open to discussion on this point, though.
dan-perron commentedon Jul 20, 2016
Is there a timeline for V1?
I'd consider creating a patch if you'd be interested in the feature (and it's going to be released in the near future)
hypesystem commentedon Jul 20, 2016
The timeline is "when we've checked most or all things off our list" #238 -- my best guess is quite soon after my summer holiday is up. Early to mid september, probably.
dan-perron commentedon Jul 20, 2016
Fair enough. Starting to chew on this a little bit.
Can you explain the rationale behind using nextTick for calling callbacks in many places rather than calling them directly?
Let me know if there's a better place to post a question like this.
hypesystem commentedon Jul 20, 2016
A function that takes a callback should never call that callback before yielding to the event loop. Using http or fs or similar usually does this, but for consistency it may slmetimes be necessary to do this explicitly.
It is commonly expected that code like this will always print "b" before "a":
Calling the callback directly in the cases you refer to would result in "a" being printed before "b".
eladnava commentedon Jul 20, 2016
This post also covers it nicely:
https://howtonode.org/understanding-process-next-tick
Consider this example taken from the post:
In the above case, if for some reason, net.connect() invoked the callback directly without
process.nextTick, the callback would be called immediately, and hence theclientvariable will not be initialized when the it's accessed by the callback to write to the client!eladnava commentedon Jul 20, 2016
And for what it's worth, I'd love for promises to be supported out of the box in v1. I personally yield promises in generator functions in most of my projects and I hate having to promisify or thunkify external library functions manually. I love it when libraries provide either a callback or promise interface (if a callback is omitted).
hypesystem commentedon Jul 20, 2016
Alright :-) let's do it
dan-perron commentedon Jul 21, 2016
For your consideration #264
eladnava commentedon Oct 3, 2016
Closing this as PR was merged successfully. 😄