You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example is written in typescript (to show types) and purely hypothetical as a demonstration :
constbuffer: Uint8Array=newUint8Array(1e6);letoffset: number=0;constwritableStream: WritableStream<number>=newWritableStream<number>({write(byte: number){buffer[offset++]=byte;// here we can return a promise indicating when the write is done,// but we cannot provide any feedback about the value of offset for example},context(...args: any[]){// purely hypotheticalreturn{offset: offset};}});constwriter: WritableStreamDefaultWriter<number>=writableStream.getWriter();
/** in a separate context where only writer is available (ex: in a function) **/asyncfunctionfoo(writer: WritableStreamDefaultWriter<number>): boolean{// this could be interesting to have access to some contextual dataconstoffset: number=writer.getContext().offset;// of course impossible because not definedif(offset>5){awaitwriter.write(2);}else{awaitwriter.write(1);// a void promise is always returned}}
Without the possibility to extends WritableStreamDefaultWriter (as an es6 class) or having a specific method (like getContext()), it's pretty hard to get an detailed answer of the write (same for read). What I noticed, is was that the write only returns success or failed (intentional and probably the best), we don't have any idea of the contextual state of the writable stream. The queuing strategy with backpressure does a lot of but in some case we need more.
I could be for example interested to change the value of the next .write() according to what send me back the writer.
The two only solutions I see here are :
pass getContext() as a callback
or extend WritableStreamDefaultWriter with Object.definyProperty
... but none of them sound really elegant to me.
So we could maybe extends the UnderlyingSink with context and add getContext() to the writer ? Or have you any idea how to solve this dilemma ?
The text was updated successfully, but these errors were encountered:
Ok, this is what I was thinking, I was just wondering if someone already addressed this "issue".
In my example, foo could be really far in the stack (imagine a a->b->c->....->z->foo) and passing every time getContext and writer could be a pain. offset cannot be directly passed because it evolves with the call of write. So a valid solution could be to pass an object { writer, getOffset } instead but less cool than having the possibility to extend the writer ;)
I'll let open this issue 1~2 days if somebody else could be interested, and I'll close it after. Thanks for your answer.
This example is written in typescript (to show types) and purely hypothetical as a demonstration :
Without the possibility to extends WritableStreamDefaultWriter (as an es6 class) or having a specific method (like
getContext()
), it's pretty hard to get an detailed answer of the write (same for read). What I noticed, is was that the write only returns success or failed (intentional and probably the best), we don't have any idea of the contextual state of the writable stream. The queuing strategy with backpressure does a lot of but in some case we need more.I could be for example interested to change the value of the next
.write()
according to what send me back the writer.The two only solutions I see here are :
getContext()
as a callbackWritableStreamDefaultWriter
withObject.definyProperty
... but none of them sound really elegant to me.
So we could maybe extends the UnderlyingSink with
context
and addgetContext()
to the writer ? Or have you any idea how to solve this dilemma ?The text was updated successfully, but these errors were encountered: