-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
feat(core): streams #12596
feat(core): streams #12596
Conversation
/// All objects that can be store in the resource table should implement the | ||
/// `Resource` trait. | ||
/// TODO(@AaronO): investigate avoiding alloc on read/write/shutdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am pretty certain that boxing the returned future is unavoidable with trait methods.
It'd be nice though if we could avoid double boxing.
Since read/write/shutdown are now builtin ops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about sync APIs?
Since sync APIs are only used for file IO (on This would leave them out from IO metrics in core, but this is easy to reconsider down the line |
Okay, keep in mind that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't see why these ops should return Option<AsyncResult<_>>
rather than AsyncResult<_>
.
IMO that's just un-ergonomic and the "op not supported by this resource type" case really doesn't need any optimization.
Or am I missing something?
I think the "ergonomics" of the trait weren't a priority for a first pass given the limited amount of callers. The plan was to tweak and evolve this. I still generally don't like the idea that we have to peek into errors to know if the stream was readable or not. But regardless I've dropped the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This allows resources to be "streams" by implementing read/write/shutdown, returning
None
if not implemented andSome(future)
otherwise.These streams are implicit since their nature (read/write/duplex) isn't known until called, but we could easily add another method to explicitly tag resources as streams.
op_read/op_write/op_shutdown are now builtin ops provided by
deno_core
Note: this current implementation is simple & straightforward but it results in an additional alloc per read/write call
Closes #12556