From 3e87f6d2c6755ff150bd644e5b1091bf89a68eb3 Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Wed, 10 Oct 2018 12:46:10 -0400 Subject: [PATCH] fix(subscription): promisify Subscription#close --- src/subscriber.js | 9 ++++++++- test/subscriber.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/subscriber.js b/src/subscriber.js index 63712e876..7f018fc42 100644 --- a/src/subscriber.js +++ b/src/subscriber.js @@ -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'); @@ -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; diff --git a/test/subscriber.js b/test/subscriber.js index bf4f35b33..edb8def8e 100644 --- a/test/subscriber.js +++ b/test/subscriber.js @@ -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() { @@ -67,6 +74,7 @@ describe('Subscriber', function() { '../src/util': fakeUtil, '@google-cloud/promisify': { promisify: fakePromisify, + promisifyAll: fakePromisifyAll, }, delay: fakeDelay, os: fakeOs, @@ -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); });