nolocal-block-on
Version of futures_lite::future::block_on
that does not use any thread locals internally. This is a very specialized crate designed for use in special parts of a program (such as in libc::atexit
callbacks, or things occurring pre- or post- main) where thread local storage will not function.
If your future itself uses thread-local storage, though, then you're out of luck (or need to change the implementation of the futures you're using).
You almost certainly want the normal futures_lite::future::block_on
except in specific circumstances as described above.
Examples
The way you invoke the function provided by this crate is the same as the futures-lite
version:
let val = block_on;
assert_eq!;
However, the futures-lite
version does not work in (rare) places where thread-local storage cannot function - for example, running after the main rust runtime is getting shut down. To illustrate this, we demonstrate it via libc::atexit
.
The following code, using futures_lite::future::block_on
, might panic due to using thread-locals in the implementation - and in particular, when multiple threads are involved (such as with blocking::Unblock
), it will panic consistently:
use ;
use Mutex;
use ;
use Unblock;
static STDOUT: = new;
block_on;
extern "C"
unsafe
However, the following code using nolocal_block_on::block_on
, will not panic, as the implementation doesn't use any thread-locals (for non-trivial futures, you might need to check to make sure they don't use thread-locals in their implementations):
use block_on;
use AsyncWriteExt;
use Mutex;
use ;
use Unblock;
static STDOUT: = new;
block_on;
extern "C"
unsafe