Function moxie::load_once [−][src]
pub fn load_once<Fut, Output>(init: impl FnOnce() -> Fut) -> Poll<Output> where
Fut: Future<Output = Output> + 'static,
Output: Clone + 'static,
Expand description
Calls load_with
, never re-initializes the loading future, and clones the
returned value on each revision once the future has completed and returned.
Example
use futures::{channel::oneshot, executor::LocalPool};
use moxie::{load_once, runtime::RunLoop};
use std::task::Poll;
let (sender, receiver) = oneshot::channel();
let mut receiver = Some(receiver);
let mut rt = RunLoop::new(|| load_once(|| receiver.take().unwrap()));
let mut exec = LocalPool::new();
rt.set_task_executor(exec.spawner());
assert_eq!(rt.run_once(), Poll::Pending);
exec.run_until_stalled();
assert_eq!(rt.run_once(), Poll::Pending);
sender.send(()).unwrap();
assert_eq!(rt.run_once(), Poll::Pending);
exec.run();
assert_eq!(rt.run_once(), Poll::Ready(Ok(())));
Environment Expectations
This function requires the following types to be visible to illicit::get
and will
panic otherwise:
Context