component-model icon indicating copy to clipboard operation
component-model copied to clipboard

Is `copy-result.cancelled` useful?

Open lann opened this issue 4 months ago • 1 comments

It appears that when a stream operation is cancelled the resulting copy-result could be either completed or cancelled. Given that the caller "knows" it has cancelled the stream is there any semantic difference between these two results? If not, could the cancelled code be removed?

lann avatar Aug 29 '25 18:08 lann

Yeah, that's a good question. I believe that in some very-async I/O scenarios where cancellation itself is an async operation, calling stream.cancel-read races with completion of the stream.read and so the separate "completed" and "cancelled" cases tell you "which one won the race". One example of where this could be meaningful (which IIRC was the original motivation) is for zero-length reads/writes where "completed" means "the other side is ready". Another case might be: if a read "completed" with less than the buffer size, that might mean that it's unlikely there is more imminently pending (b/c otherwise more would've been copied).

lukewagner avatar Aug 29 '25 20:08 lukewagner