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

[WritableStream] Locking semantics #474

Closed
tyoshino opened this issue Jul 5, 2016 · 4 comments
Closed

[WritableStream] Locking semantics #474

tyoshino opened this issue Jul 5, 2016 · 4 comments

Comments

@tyoshino
Copy link
Member

tyoshino commented Jul 5, 2016

For ReadableStream, we specified the lock to be releasable only when there's no pending read().

For WritableStream, what should we do? While any write() is pending (returned promise is pending), a writer shouldn't be releasable? This means that while the queue is not empty, a writer cannot be released.

So, the queuing mechanism serves to single consumer. Does this sound right?

@domenic
Copy link
Member

domenic commented Jul 6, 2016

Hmm. I don't see many advantages to adding this restriction.

Part of the advantage of having a writable stream is to allow "fire and forget" writing: write(), write(), write(), write(), then go do something else. Maybe "something else" is close(), maybe it is releaseLock() and let someone else start their writing.

I would rather allow releasing the lock with pending writes, and just have further writes from a new exclusive writer go to the same queue.

@tyoshino
Copy link
Member Author

Agreed. So, I'll change the locking to allow releasing writer with pending write()s.

Then, we can say that on both ReadableStream and WritableStream a lock is unreleasable while there's pending operation on the internal queue. WritableStream doesn't have any async operation regarding the queue, and therefore a lock can be released anytime.

BTW, was there any good reason for which we made the readable stream lock unreleasable? reader.closed must become unavailable to allow the next lock acquirer to hide state, but pending read() can be fulfilled remotely without any concern?

@domenic
Copy link
Member

domenic commented Jul 12, 2016

I think our reasoning is that that was likely to be a programming error, but I am not sure...

@tyoshino
Copy link
Member Author

tyoshino commented Aug 1, 2016

I think our reasoning is that that was likely to be a programming error, but I am not sure...

OK... Me neither.

We could relax ReadableStream's constraint, too if it turns out to be useful.

In #488, I've relaxed the constraint for WritableStream. Not the WritableStreamDefaultWriter's releaseLock() doesn't check whether there're pending writes or not. I've added a TODO in the OP to document the difference between RS and WS.

@tyoshino tyoshino closed this as completed Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants