-
Notifications
You must be signed in to change notification settings - Fork 116
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
tokio_core::reactor::Core can't be stored in a global variable #75
Comments
You are correct that Hope this helps |
That is very helpful. Thanks! |
I can't figure out how to use this... Normally we need to:- // Create an event loop
let mut core = Core::new().unwrap();
// Create a future using a handle to the event loop
let socket = TcpStream::connect(&addr, &core.handle());
// Do stuff with the future...
// And then actually run the future using `core.run()`
let (_, data) = core.run(response).unwrap(); I understand an instance to remote.spawn(|handle| {
// Create a future using a handle to the event loop
let socket = TcpStream::connect(&addr, handle);
// Do stuff with the future...
}); How then do I actually perform the final step. That is, run the future? |
So, there is a bit of boiler plate right now, I'll file an issue to track discussing it... let (tx, rx) = futures::oneshot();
remote.spawn(|handle| {
TcpStream::connect(&addr, handle)
.and_then(|socket| {
let resp = do_things_with_socket(socket);
resp.and_then(|res| {
tx.complete(res);
Ok(())
})
})
});
let res = rx.wait(); |
Awesome, thanks! |
It's my understanding that only one instance of
tokio_core::reactor::Core
should be used for the entire lifetime of the program so I think having this instance in a global variable would be nice. So I tried making this instance thread safe by wrapping it in aRwLock
and storing it usinglazy_static!
:-However, this gives me the following error:-
This traces back to
mio
but I figured since @carllerche is also a member of this team it might be better to put it here.The text was updated successfully, but these errors were encountered: