Description
Feature Request
Hi, I checked the examples and the documentation, and couldn't find a way to choose my own executor to use with tide. I was wondering if there is a way to do this.
Note: Cross posted on the actix-web repository.
Detailed Description
Consider the basic example shown in this repository:
fn main() -> Result<(), std::io::Error> {
let mut app = tide::App::new();
app.at("/").get(async move |_| "Hello, world!");
Ok(app.run("127.0.0.1:8000")?)
}
On which Executor does this app run? Is there a way to provide my own Executor?
Context
Let me explain why I want to do this: I have some code that uses Futures 0.3 and creates a TCP server. I would like to have all the code work together on one Executor, so for example, during the processing of some HTTP request I will be able to send something asynchronously through my TCP server.
One workaround I was thinking about is creating a new executor, having my other server run there and create a channel::mpsc
to send messages from the tide HTTP server to my TCP server. I haven't tried it yet, I was wondering if this should actually work.
I am sure that most users that care about async request handling do some other kind of asynchronous processes (Otherwise, why would they need async request handling from the first place). I see no reason why those other asynchronous processes can't run on the same Executor.
Possible Implementation
An example of how this would look like is inspired by the aiohttp library (Python). See for example this piece of code:
import aiohttp
import asyncio
async def fetch(session, url):
async with session.get(url) as response:
return await response.text()
async def main():
async with aiohttp.ClientSession() as session:
html = await fetch(session, 'http://python.org')
print(html)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
In the example above it can be seen that aiohttp
plays like a good citizen in the async world. It creates one future state machine, and finally the user of the library can put this state machine into any loop he wants. (loop
can be seen as python's equivalent for Rust Futures's Executor
).