Skip to content

Commit

Permalink
chore: log error if causing sink to return fails
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Nov 11, 2023
1 parent 198cb6a commit 0f5e49c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/muxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ export class YamuxMuxer implements StreamMuxer {
const iterator = getIterator(source)

if (iterator.return != null) {
void iterator.return()
const res = iterator.return()

if (isPromise(res)) {
res.catch(err => {
this.log?.('could not cause sink source to return', err)
})
}
}
}

Expand Down Expand Up @@ -573,3 +579,7 @@ export class YamuxMuxer implements StreamMuxer {
})
}
}

function isPromise <T = unknown> (thing: any): thing is Promise<T> {
return thing != null && typeof thing.then === 'function'
}

0 comments on commit 0f5e49c

Please sign in to comment.