Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of operations in API design #14

Closed
backkem opened this issue Sep 21, 2023 · 1 comment
Closed

Order of operations in API design #14

backkem opened this issue Sep 21, 2023 · 1 comment

Comments

@backkem
Copy link
Collaborator

backkem commented Sep 21, 2023

In the current API design, many objects are constructed as follows:

await peerA.connect({ /* ... */ });
peerA.addEventListener("message", function (event) { /* ... */ });

An active constructor is called and only afterwards the event listeners are attached. Technically, it is possible for a message to arrive before the corresponding listener is attached.

One way to avoid this is to specify that the user agent should buffer incoming events until the event listener is attached. However, it seems advisable to avoid this altogether and redesign the API as in the following sudo-code example:

let pc = new LP2PConnection( peerA );
pc.addEventListener("message", function (event) { /* ... */ });
await pc.start({ /* ... */ });

Examples of related APIs that do this include the Presentation, ORTC and p2p-webtransport APIs.

@backkem
Copy link
Collaborator Author

backkem commented Dec 4, 2023

Considered closed by #23.

@backkem backkem closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant