Skip to content

Commit

Permalink
Merge branch 'master' into nodejs-pubsub-tb-dev-01
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenqlogic authored Jan 15, 2019
2 parents 26fec01 + 6fb9e42 commit f62c061
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface CreateSnapshotCallback {
}

/**
* @typedef {array} CreateSnapshotResponse
* @property {Snapshot}.
* @property {object} 1 The full API response.
Expand Down
15 changes: 12 additions & 3 deletions src/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import {promisifyAll} from '@google-cloud/promisify';
import {EventEmitter} from 'events';
import * as extend from 'extend';

import {CallOptions} from 'google-gax';
import {google} from '../proto/pubsub';
import * as is from 'is';
import * as snakeCase from 'lodash.snakecase';

import {google} from '../proto/pubsub';

import {CreateSnapshotCallback, CreateSnapshotResponse, CreateSubscriptionCallback, CreateSubscriptionResponse, ExistsCallback, GetCallOptions, Metadata, PubSub, PushConfig, RequestCallback, SubscriptionCallOptions} from '.';

import {IAM} from './iam';
import {Snapshot} from './snapshot';
import {Subscriber, SubscriberOptions} from './subscriber';
Expand Down Expand Up @@ -199,13 +199,15 @@ export class Subscription extends EventEmitter {
create!: Function;
iam: IAM;
name: string;

metadata: Metadata;
request: Function;
private _subscriber: Subscriber;
constructor(pubsub: PubSub, name: string, options?: SubscriptionCallOptions) {
super();



options = options || {};

this.pubsub = pubsub;
Expand Down Expand Up @@ -296,6 +298,7 @@ export class Subscription extends EventEmitter {
close(): Promise<void>;
close(callback: RequestCallback<void>): void;
close(callback?: RequestCallback<void>): void|Promise<void> {

this._subscriber.close().then(() => callback!(), callback);
}
/**
Expand Down Expand Up @@ -409,6 +412,7 @@ export class Subscription extends EventEmitter {
* });
*/


delete(callback: RequestCallback<google.protobuf.Empty>): void;
delete(gaxOpts?: CallOptions): Promise<google.protobuf.Empty>;
delete(
Expand All @@ -422,6 +426,7 @@ export class Subscription extends EventEmitter {
typeof gaxOptsOrCallback === 'object' ? gaxOptsOrCallback : {};
callback =
typeof gaxOptsOrCallback === 'function' ? gaxOptsOrCallback : callback;

callback = callback || noop;
const reqOpts = {
subscription: this.name,
Expand All @@ -439,13 +444,15 @@ export class Subscription extends EventEmitter {
gaxOpts,
},


(err: Error, resp: google.protobuf.Empty) => {
if (!err) {
this.removeAllListeners();
this.close();
}
callback!(err, resp);
});

}
/**
* @typedef {array} SubscriptionExistsResponse
Expand Down Expand Up @@ -806,9 +813,11 @@ export class Subscription extends EventEmitter {
};

if (is.string(snapshot)) {

reqOpts.snapshot =
Snapshot.formatName_(this.pubsub.projectId, snapshot.toString());


} else if (is.date(snapshot)) {
reqOpts.time = snapshot as Date;
} else {
Expand Down

0 comments on commit f62c061

Please sign in to comment.