Skip to content

Commit 7ea928d

Browse files
committed
some explaining comments
1 parent ef198e8 commit 7ea928d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/peer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,13 @@ export class Peer extends EventEmitter<PeerEvents> implements IPeer {
284284
onfulfilled?: (value: IPeer) => any,
285285
onrejected?: (reason: PeerError) => any,
286286
) => {
287+
// Remove 'then' to prevent potential recursion issues
288+
// `await` will wait for a Promise-like to resolve recursively
287289
delete this.then;
288-
this.once("open", () => onfulfilled?.(this));
290+
291+
// We don’t need to worry about cleaning up listeners here
292+
// `await`ing a Promise will make sure only one of the paths executes
293+
this.once("open", () => onfulfilled(this));
289294
this.once("error", onrejected);
290295
};
291296

0 commit comments

Comments
 (0)