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

API Design: EventHandler vs ReadableStream #30

Closed
backkem opened this issue Dec 22, 2023 · 1 comment
Closed

API Design: EventHandler vs ReadableStream #30

backkem opened this issue Dec 22, 2023 · 1 comment

Comments

@backkem
Copy link
Collaborator

backkem commented Dec 22, 2023

While working on the LP2PQuicTransport interface in #28 I noticed that the WebTransport spec doesn't define a single EventHandler, instead a ReadableStream is used in many cases. As an expertise, here is a comparison based on the LP2PQuicTransportEvent event:

EventHandler (As currently defined)

interface LP2PReceiver : EventTarget  {
  attribute EventHandler ontransport;
  Promise<undefined> start();
};

Usage:

const receiver = new LP2PReceiver();

receiver.ontransport = e => {
    const transport = e.transport;
    await transport.ready;
}

await receiver.start();

ReadableStream (hypothetical)

interface LP2PReceiver {
  readonly attribute Promise<undefined> ready;
  /* a ReadableStream of LP2PQuicTransport objects */
  readonly attribute ReadableStream incomingTransports;
};

Usage:

const receiver = new LP2PReceiver();

for await (const transport of receiver.incomingTransports) {
    await transport.ready;
}

Note that this example assumes a LP2PReceiver is started on creation. The usage example assumes support for Async iterable using for await ... of in the absence of which the code becomes slightly more involved.

I opened this issue to discuss what kind of design we prefer and/or if mixed use seems appropriate. E.g.: combining onconnection with incomingTransports to match the precedent in their respective API, see #29.

@backkem
Copy link
Collaborator Author

backkem commented Jan 9, 2024

#33 aligns the WebTransport part of the API as described above; closing.

@backkem backkem closed this as completed Jan 9, 2024
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