Skip to content

Conversation

@callmehiphop
Copy link
Contributor

@callmehiphop callmehiphop commented Oct 14, 2016

This makes operations Promise friendly. By default they are still EventEmitter instances, but now include a .promise() method as a convenience.

bigquery.startQuery(query)
  .then(function(data) {
    var job = data[0];
    return job.promise();
  })
  .then(function(data) {
    var metadata = data[0];
  }, function(err) {
    // Something went wrong!
  });

With Bluebird

bigquery.startQuery(query)
  .spread(function(job) {
    return job.promise();
  })
  .spread(function(metadata) {
    // yay
  });

In Node >= 6.0:

bigquery.startQuery(query)
  .then([job] => job.promise())
  .then([metadata] => {}, err => {});

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 14, 2016
* Wraps the `complete` and `error` events in a Promise.
*
* @return {promise}
*/

This comment was marked as spam.

This comment was marked as spam.

* }, function(err) {
* // An error occurred during the job.
* });
*/

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

Idea and code lgtm.

*/
Job.prototype.promise = function() {
var self = this;

This comment was marked as spam.

This comment was marked as spam.

@callmehiphop
Copy link
Contributor Author

@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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants