-
Notifications
You must be signed in to change notification settings - Fork 55
Description
@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."