Skip to content

Commit c7c4c7c

Browse files
committed
events
1 parent db959b0 commit c7c4c7c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/mods/tls.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,13 @@ export class TlsStream extends EventTarget {
215215

216216
stream.readable
217217
.pipeTo(read.writable, { signal })
218-
.catch(this.error.bind(this))
218+
.then(this.onClose.bind(this))
219+
.catch(this.onError.bind(this))
219220

220221
write.readable
221222
.pipeTo(stream.writable, { signal })
222-
.catch(this.error.bind(this))
223+
.then(this.onClose.bind(this))
224+
.catch(this.onError.bind(this))
223225

224226
const trash = new WritableStream()
225227

@@ -228,7 +230,7 @@ export class TlsStream extends EventTarget {
228230
*/
229231
rtrashable
230232
.pipeTo(trash, { signal })
231-
.catch(this.error.bind(this))
233+
.catch(this.onError.bind(this))
232234
}
233235

234236
get input() {
@@ -239,18 +241,17 @@ export class TlsStream extends EventTarget {
239241
return this._output!
240242
}
241243

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
247247
}
248248

249-
error(error?: unknown) {
249+
private async onError(error?: unknown) {
250+
const event = new ErrorEvent("error", { error })
251+
if (!this.dispatchEvent(event)) return
252+
250253
try { this.input.error(error) } catch (e: unknown) { }
251254
try { this.output.error(error) } catch (e: unknown) { }
252-
253-
this.dispatchEvent(new ErrorEvent("error", { error }))
254255
}
255256

256257
async handshake() {

0 commit comments

Comments
 (0)