Skip to content

Can we feed the [[OutgoingDatagramsQueue]] without prematurely resolving write promises? #400

@jan-ivar

Description

@jan-ivar

@yutakahirano wrote in #21 (comment):

pkt_departure — I believe await writer.write(data); gives you this?

... the promise returned by writeDatagrams gives you effectively nothing.

This seems like an algorithm bug. [[OutgoingDatagramsQueue]] says: "A queue of tuples of an outgoing datagram, a timestamp and a promise which is resolved when the datagram is sent or discarded."

But that last description gels poorly with what we've written writeDatagrams to actually do: "If the length of datagrams.[[OutgoingDatagramsQueue]] is less than datagrams.[[OutgoingDatagramsHighWaterMark]], then resolve promise with undefined."

I sort of remember this: we were trying to feed the [[OutgoingDatagramsQueue]] by prematurely resolving the write promises. But is this the correct/only way? I worry we've created our own HighwaterMark algorithm, and should instead be using something in the streams spec here, but I don't know what that is or that the correct spec hooks exist. @ricea or @MattiasBuelens do you know?

In theory, there are two promises it seems a sink should be able to control 1) the one from .ready and 2) the one from .write:

  for (const datagram of datagrams) {
    await writer.ready; // 1
    writer.write(datagram).catch(() => {}); // 2
  }

If we could control 1 here, it might leave 2 to retain its original meaning of "when the datagram is sent or discarded."

Metadata

Metadata

Assignees

No one assigned

    Labels

    hardThings to discuss and think about

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions