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

core: Add ResourceTable #3150

Merged
merged 5 commits into from
Oct 23, 2019
Merged

core: Add ResourceTable #3150

merged 5 commits into from
Oct 23, 2019

Conversation

bartlomieju
Copy link
Member

Closes #3134

CC @ry

}

/// Abstract type representing resource in Deno.
pub trait Resource: Downcast + Any + Send {
Copy link
Member Author

@bartlomieju bartlomieju Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried implementing downcasting manually, but got such errors:

error[E0038]: the trait `resources::Resource` cannot be made into an object
  --> core/resources.rs:61:3
   |
61 |   pub fn add(&mut self, resource: Box<dyn Resource>) -> ResourceId {
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `resources::Resource` cannot be made into an object
   |
   = note: method `downcast_ref` has generic type parameters
   = note: method `downcast_mut` has generic type parameters

That's why I used Downcast trait from downcast-rs crate.

)
let fut = futures::future::poll_fn(move || {
let mut table = get_resource_table();
let stream = table.get_mut::<TcpStream>(rid)?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be awesome if we could do something like:

let stream = table.get_mut::<dyn AsyncWrite>(rid)?;
stream.poll_write(&zero_copy_buf)

@ry ry requested a review from piscisaureus October 21, 2019 14:14
core/resources.rs Outdated Show resolved Hide resolved
core/resources.rs Outdated Show resolved Hide resolved
core/resources.rs Outdated Show resolved Hide resolved
core/resources.rs Show resolved Hide resolved
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for this important work!
I defer to @piscisaureus to approve and land.

@bartlomieju
Copy link
Member Author

Looks great! Thank you for this important work!
I defer to @piscisaureus to approve and land.

Cool, though we shouldn't land it until we figure out how to implement read/write handling

@ry
Copy link
Member

ry commented Oct 21, 2019

Cool, though we shouldn't land it until we figure out how to implement read/write handling

The way you handled it in the example is good.

@bartlomieju
Copy link
Member Author

Cool, though we shouldn't land it until we figure out how to implement read/write handling

The way you handled it in the example is good.

Can't be translated to CLI though, PTAL at this comment

@ry
Copy link
Member

ry commented Oct 21, 2019

Can't be translated to CLI though, PTAL at this comment

I don't understand why it can't work in the CLI. It's the same operation.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@piscisaureus approves too - thanks @bartlomieju !

@ry ry merged commit 029e833 into denoland:master Oct 23, 2019
@bartlomieju bartlomieju deleted the core-resource_table branch October 23, 2019 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor: Resource table
2 participants