2 ms·
> This is solvable through a threadpool, which tokio provides. In other words, it lets you make a blue function red. I'll add that once you have this, the asyn
by Manishearth 10y ago
> This is solvable through a threadpool, which tokio provides. In other words, it lets you make a blue function red.
I'll add that once you have this, the async/sync distinction (functions that return Future and those which don't) in Rust becomes exactly the same as fallible/infallible (functions that return Result or don't) and gets handled pretty much the same way.
- fooyc 10y agoCan you "match" on the result to destructure it as well ? Without blocking the event loop ?
- Manishearth 10y agoFutures aren't enums. I meant that you have the ability to handle it there and then (block on it via threadpool), or defer handling (chain to the next async calls in your async function). You have this same pair of abilities with Option, which bridges the basically nonexistant gap between fallible and infallible functions.
- fooyc 10y agoIsn't this adding a lot of overhead compared to calling a synchronous implementation of the same code ?
- Manishearth 10y agoYou'd have to block on I/O somehow. You can avoid the threadpool costs to block, too, IIRC (but that's worse)
- fooyc 10y agoThat's the point. Calling a blocking system call is cheaper that artificially blocking on a non-blocking operation.