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.


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();

assert_eq!(rt.run_once(), Poll::Pending);
assert_eq!(rt.run_once(), Poll::Pending);


assert_eq!(rt.run_once(), Poll::Pending);;
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