Skip to content

Commit ea05e8f

Browse files
committed
Avoid a subtly async Channel.dispose method
The public `Channel.dispose` method was typed as returning `void`, but the derived `ChannelClass.dispose` method would return a promise. As a result, public clients wouldn't know to `await` the result, and if `dispose` threw an exception, that would result in an unobserved promise rejection. Since folks are not expected to await, rather than make the base method async, I made the derived method *not* async.
1 parent df19c89 commit ea05e8f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/nerdbank-streams/src/Channel.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export abstract class Channel implements IDisposableObservable {
5656
/**
5757
* Closes this channel.
5858
*/
59-
public dispose() {
59+
public dispose(): void {
6060
// The interesting stuff is in the derived class.
6161
this._isDisposed = true;
6262
}
@@ -247,7 +247,7 @@ export class ChannelClass extends Channel {
247247
}
248248
}
249249

250-
public async dispose() {
250+
public dispose(): void {
251251
if (!this.isDisposed) {
252252
super.dispose();
253253

@@ -262,7 +262,9 @@ export class ChannelClass extends Channel {
262262
this._duplex.push(null);
263263

264264
this._completion.resolve();
265-
await this._multiplexingStream.onChannelDisposed(this);
265+
266+
// Send the notification, but we can't await the result of this.
267+
caught(this._multiplexingStream.onChannelDisposed(this));
266268
}
267269
}
268270

0 commit comments

Comments
 (0)