Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The purpose of this PR is to show how to promisify the
gcloud-node
API while still maintaining support for callbacks. See #551npm test
succeeds for me. I did not try the system tests (but I can, depending on how serious we are about this pull request).Summary of changes
Breaking API changes
Service#request
, the Prediction API methods, and the ServiceObject methods now only return a single errback value (which is more idiomatic, as opposed to also passing random positional success arguments to the callback). The positional argument (e.g.apiResponse
) which was previously passed to the callback as a separate argument is now attached as a property of the singleerr
argument which is now the only value returned in the event of an error/rejection. Now, in the event of an error/rejection,err
is all you need to inspect.Backwards compatible API changes
Service#request
now returns a promise, but makes use of.asCallback
to maintain support for callbacks..asCallack
to maintain support for callbacks.ServiceObject
methods now return promises, which make use of.asCallback
to maintain support for callbacks.bluebird
Other
Service#request
, to take into account the new promisified methods.Note: Many methods return multiple values. If you use callbacks, the multiple values will still be passed to your callback as multiple positional arguments. But if you use Promises,
.then
will receive an array containing the return values, so make use of.spread
instead.Note 2: My first commit did not do anything about streams, which still need to be addressed.
Note 3: I'm not sure I completely promisified
ServiceObject
, as I haven't spent enough time studying the code. In fact I'm sure I didn't promisify it completely, because I would have expected to have needed to refactor more tests than I did.