Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Commit 474d08b

Browse files
authored
Merge branch 'master' into master
2 parents 2c3c5f2 + e421749 commit 474d08b

3 files changed

Lines changed: 23 additions & 58 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node: [10, 12, 13]
12+
node: [10, 12, 14, 15]
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-node@v1
@@ -19,7 +19,9 @@ jobs:
1919
# The first installation step ensures that all of our production
2020
# dependencies work on the given Node.js version, this helps us find
2121
# dependencies that don't match our engines field:
22-
- run: npm install --production --engine-strict
22+
- run: npm install --production --engine-strict --ignore-scripts --no-package-lock
23+
# Clean up the production install, before installing dev/production:
24+
- run: rm -rf node_modules
2325
- run: npm install
2426
- run: npm test
2527
- name: coverage
@@ -33,7 +35,7 @@ jobs:
3335
- uses: actions/checkout@v2
3436
- uses: actions/setup-node@v1
3537
with:
36-
node-version: 12
38+
node-version: 14
3739
- run: npm install
3840
- run: npm test
3941
- name: coverage
@@ -47,7 +49,7 @@ jobs:
4749
- uses: actions/checkout@v2
4850
- uses: actions/setup-node@v1
4951
with:
50-
node-version: 12
52+
node-version: 14
5153
- run: npm install
5254
- run: npm run lint
5355
docs:
@@ -56,6 +58,6 @@ jobs:
5658
- uses: actions/checkout@v2
5759
- uses: actions/setup-node@v1
5860
with:
59-
node-version: 12
61+
node-version: 14
6062
- run: npm install
6163
- run: npm run docs-test

src/message-stream.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ export interface MessageStreamOptions {
127127
* @param {MessageStreamOptions} [options] The message stream options.
128128
*/
129129
export class MessageStream extends PassThrough {
130-
destroyed: boolean;
131130
private _keepAliveHandle: NodeJS.Timer;
132131
private _fillHandle?: NodeJS.Timer;
133132
private _options: MessageStreamOptions;
@@ -139,7 +138,6 @@ export class MessageStream extends PassThrough {
139138

140139
super({objectMode: true, highWaterMark: options.highWaterMark});
141140

142-
this.destroyed = false;
143141
this._options = options;
144142
this._retrier = new PullRetry();
145143
this._streams = new Map();
@@ -156,14 +154,24 @@ export class MessageStream extends PassThrough {
156154
/**
157155
* Destroys the stream and any underlying streams.
158156
*
159-
* @param {error?} err An error to emit, if any.
157+
* @param {error?} error An error to emit, if any.
160158
* @private
161159
*/
162-
destroy(err?: Error): void {
160+
destroy(error?: Error | null): void {
161+
// We can't assume Node has taken care of this in <14.
163162
if (this.destroyed) {
164163
return;
165164
}
166-
165+
super.destroy(error ? error : undefined);
166+
}
167+
/**
168+
* Destroys the stream and any underlying streams.
169+
*
170+
* @param {error?} error An error to emit, if any.
171+
* @param {Function} callback Callback for completion of any destruction.
172+
* @private
173+
*/
174+
_destroy(error: Error | null, callback: (error: Error | null) => void): void {
167175
this.destroyed = true;
168176
clearInterval(this._keepAliveHandle);
169177

@@ -172,16 +180,7 @@ export class MessageStream extends PassThrough {
172180
stream.cancel();
173181
}
174182

175-
if (typeof super.destroy === 'function') {
176-
return super.destroy(err);
177-
}
178-
179-
process.nextTick(() => {
180-
if (err) {
181-
this.emit('error', err);
182-
}
183-
this.emit('close');
184-
});
183+
callback(error);
185184
}
186185
/**
187186
* Adds a StreamingPull stream to the combined stream.

test/message-stream.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import * as assert from 'assert';
18-
import {describe, it, before, beforeEach, afterEach, after} from 'mocha';
18+
import {describe, it, before, beforeEach, afterEach} from 'mocha';
1919
import {grpc} from 'google-gax';
2020
import * as proxyquire from 'proxyquire';
2121
import * as sinon from 'sinon';
@@ -302,13 +302,7 @@ describe('MessageStream', () => {
302302

303303
describe('destroy', () => {
304304
it('should noop if already destroyed', done => {
305-
sandbox
306-
.stub(FakePassThrough.prototype, 'destroy')
307-
.callsFake(function (this: Duplex) {
308-
if (this === messageStream) {
309-
done();
310-
}
311-
});
305+
messageStream.on('close', done);
312306

313307
messageStream.destroy();
314308
messageStream.destroy();
@@ -350,36 +344,6 @@ describe('MessageStream', () => {
350344
assert.strictEqual(stub.callCount, 1);
351345
});
352346
});
353-
354-
describe('without native destroy', () => {
355-
let destroy: (err?: Error) => void;
356-
357-
before(() => {
358-
destroy = FakePassThrough.prototype.destroy;
359-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
360-
FakePassThrough.prototype.destroy = false as any;
361-
});
362-
363-
after(() => {
364-
FakePassThrough.prototype.destroy = destroy;
365-
});
366-
367-
it('should emit close', done => {
368-
messageStream.on('close', done);
369-
messageStream.destroy();
370-
});
371-
372-
it('should emit an error if present', done => {
373-
const fakeError = new Error('err');
374-
375-
messageStream.on('error', err => {
376-
assert.strictEqual(err, fakeError);
377-
done();
378-
});
379-
380-
messageStream.destroy(fakeError);
381-
});
382-
});
383347
});
384348

385349
describe('pull stream lifecycle', () => {

0 commit comments

Comments
 (0)