core: make operations promise friendly#1689
core: make operations promise friendly#1689stephenplusplus merged 5 commits intogoogleapis:promise-supportfrom callmehiphop:promise-support-3
Conversation
| * Wraps the `complete` and `error` events in a Promise. | ||
| * | ||
| * @return {promise} | ||
| */ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/bigquery/src/job.js
Outdated
| * }, function(err) { | ||
| * // An error occurred during the job. | ||
| * }); | ||
| */ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Idea and code lgtm. |
| */ | ||
| Job.prototype.promise = function() { | ||
| var self = this; | ||
|
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@stephenplusplus tests have been added, PTAL! |
| Job.prototype.promise = function() { | ||
| var self = this; | ||
|
|
||
| return new self.Promise(function(resolve, reject) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| GrpcOperation.prototype.promise = function() { | ||
| var self = this; | ||
|
|
||
| return new self.Promise(function(resolve, reject) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This makes operations Promise friendly. By default they are still
EventEmitterinstances, but now include a.promise()method as a convenience.With Bluebird
In Node >= 6.0: