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, 

Calls load_with but never re-initializes the loading future.


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

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: