4 ms·
If your program is mostly synchronous, you can manually create the async runtime and just use block_on to call async functions from a sync context: https://toki
by kirbyfan64sos 4y ago
If your program is mostly synchronous, you can manually create the async runtime and just use block_on to call async functions from a sync context: https://tokio.rs/tokio/topics/bridging#a-synchronous-interface-to-mini-redis https://tokio.rs/tokio/topics/bridging#a-synchronous-interfa...
- abiro 4y agoEven simpler to use `futures::executor::block_on`. No need to create a runtime, you can just call the function. https://docs.rs/futures/latest/futures/executor/fn.block_on.html https://docs.rs/futures/latest/futures/executor/fn.block_on....
- Matthias247 4y agoThat will only allow to run futures which have no IO dependency. Other typically expect a certain runtime to be running, because they eg use the epoll loop of that runtime to make progress.
- mamcx 4y agoNo, this not work well. The highly infectious nature of async means you need to do that A LOT. ie: reverse ALL things await. That is too much. I refactor all my codebase (a huge refactor!) because this.
- jen20 4y agoWhat would you prefer the alternative to be? Library authors to do dual implementations of everything?
- slightknack 4y agoA language with a function-color-agnostic effect system, generic over asynchronicity?
- Georgelemental 4y agohttps://news.ycombinator.com/item?id=31620340 https://news.ycombinator.com/item?id=31620340