Skip to content
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

fix(subscription): promisify Subscription#close #282

Merged
merged 2 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const arrify = require('arrify');
const chunk = require('lodash.chunk');
const util = require('./util');
const {promisify} = require('@google-cloud/promisify');
const {promisify, promisifyAll} = require('@google-cloud/promisify');
const delay = require('delay');
const {EventEmitter} = require('events');
const extend = require('extend');
Expand Down Expand Up @@ -473,4 +473,11 @@ class Subscriber extends EventEmitter {
}
}

/*! Developer Documentation
*
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
promisifyAll(Subscriber);

module.exports = Subscriber;
12 changes: 12 additions & 0 deletions test/subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ function fakePromisify() {
return (promisifyOverride || pfy.promisify).apply(null, arguments);
}

let promisified = false;
function fakePromisifyAll(Class) {
if (Class.name === 'Subscriber') {
promisified = true;
}
}

const FAKE_FREE_MEM = 168222720;
const fakeOs = {
freemem: function() {
Expand Down Expand Up @@ -67,6 +74,7 @@ describe('Subscriber', function() {
'../src/util': fakeUtil,
'@google-cloud/promisify': {
promisify: fakePromisify,
promisifyAll: fakePromisifyAll,
},
delay: fakeDelay,
os: fakeOs,
Expand All @@ -81,6 +89,10 @@ describe('Subscriber', function() {
});

describe('initialization', function() {
it('should promisify all the things', function() {
assert(promisified);
});

it('should create a histogram instance', function() {
assert(subscriber.histogram instanceof FakeHistogram);
});
Expand Down