[][src]Function rxrust::observable::from_future

pub fn from_future<F, Item>(
    f: F
) -> ObservableOnce<impl FnOnce(Box<dyn Observer<Item, ()> + Send>), Item, ()> where
    F: FutureExt<Output = Item> + Send + 'static,
    Item: 'static, 

Converts a Future to an observable sequence. Even though if the future poll value has Result::Err type, also emit as a normal value, not trigger to error handle.

let res = Arc::new(Mutex::new(0));
let c_res = res.clone();
use futures::future;
observable::from_future(future::ready(1))
  .subscribe(move |v| {
    *res.lock().unwrap() = *v;
  });
std::thread::sleep(std::time::Duration::new(1, 0));
assert_eq!(*c_res.lock().unwrap(), 1);

If your Future poll an Result type value, and you want dispatch the error by rxrust, you can use from_future_with_err