Module fbp::fbp_asyncstate [−][src]
Expand description
An asynchronous state change monitor
Given the asynchronous nature of FBP nodes there are times when code may need to wait until an asynchronous state has changed. The AsyncState state provides for that need
Example
use futures::*;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::sync::Arc;
use std::sync::atomic::{Ordering, AtomicBool};
use std::ops::{Deref};
use fbp::fbp_asyncstate::*;
use std::{thread, time};
async fn asyncstate_ex() {
let my_asyncstate = AsyncState::new();
assert_eq!(my_asyncstate.is_ready(), false);
// Clone the async_state for use inside the thread
let clone_asyncsatate = my_asyncstate.clone();
let jh = thread::spawn(move || {
thread::sleep(time::Duration::from_secs(1));
clone_asyncsatate.clone().set_is_ready(true);
});
// A clone is needed because the await actually runs a
// thread that polls the state
// This will block until the state is changed inside the thread
my_asyncstate.clone().await;
assert_eq!(my_asyncstate.is_ready(), true);
let _ = jh.join();
}
Structs
Provides the structure of an AsyncState