Skip to content

Commit

Permalink
some explaining comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasgloning committed Aug 30, 2023
1 parent ef198e8 commit 7ea928d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,13 @@ export class Peer extends EventEmitter<PeerEvents> implements IPeer {
onfulfilled?: (value: IPeer) => any,
onrejected?: (reason: PeerError) => any,
) => {
// Remove 'then' to prevent potential recursion issues
// `await` will wait for a Promise-like to resolve recursively
delete this.then;
this.once("open", () => onfulfilled?.(this));

// We don’t need to worry about cleaning up listeners here
// `await`ing a Promise will make sure only one of the paths executes
this.once("open", () => onfulfilled(this));
this.once("error", onrejected);
};

Expand Down

0 comments on commit 7ea928d

Please sign in to comment.