@@ -215,11 +215,13 @@ export class TlsStream extends EventTarget {
215
215
216
216
stream . readable
217
217
. pipeTo ( read . writable , { signal } )
218
- . catch ( this . error . bind ( this ) )
218
+ . then ( this . onClose . bind ( this ) )
219
+ . catch ( this . onError . bind ( this ) )
219
220
220
221
write . readable
221
222
. pipeTo ( stream . writable , { signal } )
222
- . catch ( this . error . bind ( this ) )
223
+ . then ( this . onClose . bind ( this ) )
224
+ . catch ( this . onError . bind ( this ) )
223
225
224
226
const trash = new WritableStream ( )
225
227
@@ -228,7 +230,7 @@ export class TlsStream extends EventTarget {
228
230
*/
229
231
rtrashable
230
232
. pipeTo ( trash , { signal } )
231
- . catch ( this . error . bind ( this ) )
233
+ . catch ( this . onError . bind ( this ) )
232
234
}
233
235
234
236
get input ( ) {
@@ -239,18 +241,17 @@ export class TlsStream extends EventTarget {
239
241
return this . _output !
240
242
}
241
243
242
- close ( ) {
243
- try { this . input . terminate ( ) } catch ( e : unknown ) { }
244
- try { this . output . terminate ( ) } catch ( e : unknown ) { }
245
-
246
- this . dispatchEvent ( new CloseEvent ( "close" ) )
244
+ private async onClose ( ) {
245
+ const event = new CloseEvent ( "close" , { } )
246
+ if ( ! this . dispatchEvent ( event ) ) return
247
247
}
248
248
249
- error ( error ?: unknown ) {
249
+ private async onError ( error ?: unknown ) {
250
+ const event = new ErrorEvent ( "error" , { error } )
251
+ if ( ! this . dispatchEvent ( event ) ) return
252
+
250
253
try { this . input . error ( error ) } catch ( e : unknown ) { }
251
254
try { this . output . error ( error ) } catch ( e : unknown ) { }
252
-
253
- this . dispatchEvent ( new ErrorEvent ( "error" , { error } ) )
254
255
}
255
256
256
257
async handshake ( ) {
0 commit comments