Function moxie::load_once_with [−][src]
pub fn load_once_with<Fut, Output, Ret>(
init: impl FnOnce() -> Fut,
with: impl FnOnce(&Output) -> Ret
) -> Poll<Ret> where
Fut: Future<Output = Output> + 'static,
Output: 'static,
Ret: 'static,
Expand description
Calls load_with
but never re-initializes the loading future.
Example
use futures::{channel::oneshot, executor::LocalPool};
use moxie::{load_once_with, runtime::RunLoop};
use std::task::Poll;
let (sender, receiver) = oneshot::channel();
let mut receiver = Some(receiver);
let mut rt = RunLoop::new(|| load_once_with(|| receiver.take().unwrap(), |res| res.clone()));
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