-
Notifications
You must be signed in to change notification settings - Fork 161
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
Efficient mapping to Unix-style APIs with pollable readers and writers #1265
Comments
I would hope that native code would use an abstraction layer on top of Maybe we can just say "if you don't use an abstraction layer, you're going to get extra copies and you'll just have to accept it"?
Sketch: we add an optional peek() method to the underlying source. It is called when Bikeshed: "peek" usually implies you get to look at the data before reading it. That would be a lot of trouble. Maybe instead have a getter called
If we use the same method name, then we have to set the return type to I would prefer to have a distinct method which does this, maybe |
To me that doesn't seem realistic because it means applications will need to write a custom I/O backend for their WASM port, since the native POSIX APIs don't work this way and Emscripten mimics a POSIX platform. We should probably reach out to WASI folks to understand what their plans are for defining I/O system calls in WASI 2.0. |
When cross-compiling code written for native platforms to WebAssembly developers need to implement the
poll
,read
andwrite
system calls on top of aReadableStream
orWritableStream
. If we make the simplifying assumption that only file descriptors opened in non-blocking mode need to be supported then we need a way to register a callback for when a stream is readable or writable and to issue a read or write which will only do as much work as can be completed synchronously.While this behavior can mostly be polyfilled (for example, by calling
read()
when a stream is polled and marking it readable when the read completes) I have not figured out a way to preserve the copy-minimizing benefits of BYOB readers because there's no way to guarantee that data is written to the BYOB buffer synchronously and so an intermediate buffer is required.This could be resolved by adding two new options to the
ReadableStreamBYOBReader
interface (and similar changes for writable streams):peek()
method which returns aPromise
that resolves when there is data in the internal queue or the underlying source has indicated that there is data available.sync: true
option toread()
which will cause it to return aReadableStreamReadResult
rather than aPromise<ReadableStreamReadResult>
if there was data in the internal queue or the underlying source responded topull()
by enqueuing a buffer synchronously. Otherwise it would returnnull
or some other sentinel value.Synchronous reads probably have to be signaled to the underlying source as well because changing the value of
byobRequest
midway through aread()
operation would likely cause problems.The text was updated successfully, but these errors were encountered: