Skip to content

Make Server core a RefCell #1151

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

Closed
wants to merge 2 commits into from
Closed

Make Server core a RefCell #1151

wants to merge 2 commits into from

Conversation

tinco
Copy link

@tinco tinco commented Apr 24, 2017

Make Server core a RefCell and introduce bind2 method that allows external core to be passed in

This is just an inspiration pull request. Do you see any problems with having core be a RefCell? I think it would be an insignificant overhead for posting new event handlers, but maybe I'm wrong and there's some tight loop that needs to dereference core?

@GitCop
Copy link

GitCop commented Apr 24, 2017

Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:

  • Commit: 54baa36
  • Commits must be in the following format: %{type}(%{scope}): %{description}

Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

@GitCop
Copy link

GitCop commented Apr 24, 2017

Thanks for contributing! Unfortunately, I'm here to tell you there were the following style issues with your Pull Request:

  • Commit: 54baa36

  • Commits must be in the following format: %{type}(%{scope}): %{description}

  • Commit: a683af7

  • Commits must be in the following format: %{type}(%{scope}): %{description}

Guidelines are available at https://github.com/hyperium/hyper/blob/master/CONTRIBUTING.md


This message was auto-generated by https://gitcop.com

@seanmonstar
Copy link
Member

Hi @tinco! Thanks for starting this up!

What is the goal here, for using a RefCell? Is this PR trying to address #1075?

@tinco
Copy link
Author

tinco commented Apr 24, 2017

Hi @seanmonstar :) Yes looks like #1075 is the sort of thing I'm trying to address. I'm trying to avoid any form of multithreading in my application, so would much prefer to have only a single Tokio core running. The idea of the Rc is that different pieces of code (with their own responsibilities) hold a reference to the core, and then the RefCell enables them to at any point borrow the core, get a handle and spawn some future on it.

I'm very much bending this API to my own selfish goal though, so I totally understand if this is not the right way for the project. Also, maybe some re-architecting could yield a more elegant solution. If there were some copyable interface to the event loop I could pass around that would be much better, but I don't know how that would work, maybe that's even something Tokio itself should think about?

@seanmonstar
Copy link
Member

You may be wanting a Handle, which lets you handle.spawn(future) on it. You can get a Handler from hyper's Server:

let server = Http::new().bind(addr, new_service)?;
let handle =server.handle();

@seanmonstar
Copy link
Member

Making use of a RefCell is probably not the way we want to go. I'm going to close this, but discussion should probably go on in #1075.

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.

3 participants