As discussed on Gitter with @bradleybeddoes, I'm missing the possibility to send new HTTP requests inside Gotham handlers because currently it's not possible to get a reference to the underlying Tokio event loop.
@bradleybeddoes pointed me to
|
fn call(&self, req: Self::Request) -> Self::Future { |
where other framework state variables are initialized. Unfortunately, I don't see a way of accessing the tokio handle in that function. As a matter of fact the whole Gotham codebase is pretty much unaware of the whole Tokio stuff because the way Gotham apps seem to be started is that the handler is passed to Hyper's server API. Hyper will either create the Tokio core internally, or let you use an existing one (since
#66).
An alternative to having Gotham put the handle reference into the state object would be to use a middleware for that: https://github.com/ChristophWurst/gotham-middleware-tokio. You can find an example usage here: https://github.com/ChristophWurst/gotham-middleware-tokio/blob/master/examples/hyper_client.rs#L22
There seem to be a few problems though. I don't know whether we should use a Handle, a Remote or let the developer choose. Handle cannot be shared across threads. However, Hyper expects a Handle rather than a Remote for its client, making it a bit cumbersome to use. The remote object does have method to get a handle, although it's not guaranteed to always get one.
This is somewhat related to hyperium/hyper#1002
@bradleybeddoes @smangelsdorf thoughts on how to integrate this in Gotham?
As discussed on Gitter with @bradleybeddoes, I'm missing the possibility to send new HTTP requests inside Gotham handlers because currently it's not possible to get a reference to the underlying Tokio event loop.
@bradleybeddoes pointed me to
gotham/src/handler/mod.rs
Line 151 in 953c39b
An alternative to having Gotham put the handle reference into the state object would be to use a middleware for that: https://github.com/ChristophWurst/gotham-middleware-tokio. You can find an example usage here: https://github.com/ChristophWurst/gotham-middleware-tokio/blob/master/examples/hyper_client.rs#L22
There seem to be a few problems though. I don't know whether we should use a
Handle, aRemoteor let the developer choose.Handlecannot be shared across threads. However, Hyper expects aHandlerather than aRemotefor its client, making it a bit cumbersome to use. The remote object does have method to get a handle, although it's not guaranteed to always get one.This is somewhat related to hyperium/hyper#1002
@bradleybeddoes @smangelsdorf thoughts on how to integrate this in Gotham?