-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 function that returns some value and takes callback for result/error #402
Comments
@thesebas yikes, that is pretty horrible, almost a reinvention of promises. In such cases it's better to write your own promisifier I think, this cannot be a common scenario. |
Well, as I said there is var request = require('request');
var req = request.post( params, callback ); // returns req object I can abort with `req.abort()` but after promisifying this lib var request = require('request');
Promise.promisifyAll(request)
request.postAsync(params) // ->returns Promise, can't inspect request in progress,
// can't abort it, etc... and I think I could find more examples, but |
As stated in the documentation and previous issues automatic promisifcation only works for method explicitly abiding the nodeback contract (including no return value). Indeed the correct way to address this is to write your own promisifier for promisifyAll (it accepts it as an option) or your own promisification method. For most of these modules (request included) there is already a package doing this on NPM. |
The default promisifier is for node callback convention, if you have something else, use a custom promisifier with the |
Ok, promisifier and this module looks "promising" and understand that this issue in general is not place of improvement bluebird, thx. |
I'd love it if bluebird were somehow able to handle cases like this. Unfortunately there are many variants and its pretty hard to cover all of them, so custom promisifiers is probably the best solution for now. This could be fixed pretty easily by node's core team though. They'd just add methods like var req = request(url);
req.readAllAsync().then(...)
// req is available for progress etc. |
If you suggest it on io.js I'd support it |
Done here, nodejs/node#153 - came up with a basic draft proposal. |
The proposal was rejected - its not going to happen. Maybe we could build a standard replacement for |
@spion dat edit :D |
Tried to use promisifyAll on sign.
I end up getting the token value inside the error. ( because it doesn't have any error param) |
@spacemonkey92 sounds like you're not actually using the promisified version. |
@phpnode That was the actual method.
This is going to the error block. |
I think that promisifying function that returns some value and takes callback for result/error makes result of this function lost, lets say there is some function that returns object for controlling this async process:
now after promisifying this function I can't access this
process
objectso what I'm missing here is some callback that I could
intercept
this returned valueMaybe creating functions that returns value and calls callback is not the best pattern but some libraries doing that already exists (for example
request
).The text was updated successfully, but these errors were encountered: