Macro completion::completion_async [−][src]
This is supported on crate features
macro
and std
only.A bang macro to generate completion async
blocks.
These async blocks evaluate to a CompletionFuture
, and you can .await
other
CompletionFuture
s inside of them.
Soundness
There is currently a slight soundness issue inside these async blocks: if you invoke an
attribute macro inside the async block on some code that awaits a completion future, and that
attribute macro moves the code to a regular, non-completion async block, you are able to create
a Future
that unsoundly wraps a CompletionFuture
. Or in code, this:
ⓘ
completion_async! { #[some_macro] completion_future.await; }
Could expand to:
ⓘ
completion_async! { async { // Oh no! We have awaited a completion future inside a regular async block. completion_future.await; } }
This macro does not require unsafe
because I decided that this unsoundness is so particular
that it is highly unlikely it will actually occur in user code. If you know of a fix for this,
it would be highly appreciated.
Examples
use completion::{FutureExt, completion_async, future}; let fut = completion_async! { let fut = async { 3 }; let completion_fut = async { 5 }.into_completion(); fut.await + completion_fut.await }; assert_eq!(future::block_on(fut), 8);