#async #minimal #executor #runtime #block-on

pollster

Synchronously block the thread until a future completes

7 releases

new 0.2.5 Jan 18, 2022
0.2.4 Apr 23, 2021
0.2.2 Mar 18, 2021
0.2.1 Jan 22, 2021
0.1.0 Apr 7, 2020

#55 in Asynchronous

Download history 5828/week @ 2021-10-01 7921/week @ 2021-10-08 7032/week @ 2021-10-15 6185/week @ 2021-10-22 5785/week @ 2021-10-29 5528/week @ 2021-11-05 5499/week @ 2021-11-12 6963/week @ 2021-11-19 5889/week @ 2021-11-26 6620/week @ 2021-12-03 7120/week @ 2021-12-10 5231/week @ 2021-12-17 3602/week @ 2021-12-24 5297/week @ 2021-12-31 6254/week @ 2022-01-07 8883/week @ 2022-01-14

24,802 downloads per month
Used in 85 crates (36 directly)

Apache-2.0/MIT

9KB
73 lines

Pollster

Pollster is an incredibly minimal async executor for Rust that lets you block a thread until a future completes.

Cargo Documentation License actions-badge

use pollster::FutureExt as _;

let my_fut = async {};

let result = my_fut.block_on();

That's it. That's all it does. Nothing more, nothing less. No need to pull in 50 crates to evaluate a future.

Why is this useful?

Now that async functions are stable, we're increasingly seeing libraries all over the Rust ecosystem expose async APIs. This is great for those wanting to build highly concurrent web applications!

However, many of us are not building highly concurrent web applications, but end up faced with an async function that we can't easily call from synchronous code. If you're in this position, then pollster is for you: it allows you to evaluate a future in-place without spinning up a heavyweight runtime like tokio or async_std.

Minimalism

Pollster is built with the UNIX ethos in mind: do one thing, and do it well. It has no dependencies, compiles quickly, and is composed of only ~100 lines of well-audited code.

Behaviour

Pollster will synchronously block the thread until a future completes. It will not spin: instead, it will place the thread into a waiting state until the future has been polled to completion.

Compatibility

Unfortunately, pollster will not work for all futures because some require a specific runtime or reactor. See here for more information about when and where pollster may be used. However, if you're already pulling in the required dependencies to create such a future in the first place, it's likely that you already have a version of block_on in your dependency tree that's designed to poll your future, so use that instead.

No runtime deps

a