allow to set context result
@@ -20,6 +20,8 @@ pub struct Context<T> where T: Service<Context=Context<T>>,
msgs: UnboundedReceiver<BoxedMessageProxy<T>>,
items: Vec<IoItem<T>>,
stream: Box<Stream<Item=<T::Message as Item>::Item, Error=<T::Message as Item>::Error>>,
+ result: Option<Result<<<T as Service>::Result as Item>::Item,
+ <<T as Service>::Result as Item>::Error>>,
}
/// io items
@@ -69,6 +71,7 @@ impl<T> Context<T> where T: Service<Context=Context<T>>
handle: handle.clone(),
stream: Box::new(stream),
items: Vec::new(),
+ result: None,
}
}
@@ -90,6 +93,11 @@ impl<T> Context<T> where T: Service<Context=Context<T>>
&self.handle
}
+ pub fn set_result(&mut self, result: Result<<<T as Service>::Result as Item>::Item,
+ <<T as Service>::Result as Item>::Error>) {
+ self.result = Some(result);
+ }
+
pub fn spawn<F>(&mut self, fut: F)
where F: CtxFuture<Item=(), Error=(), Service=T> + 'static
{
@@ -317,6 +325,14 @@ impl<T> Future for Context<T> where T: Service<Context=Context<T>>
}
}
+ // check result
+ if let Some(result) = self.result.take() {
+ match result {
+ Ok(val) => return Ok(Async::Ready(val)),
+ Err(err) => return Err(err)
+ }
+ }
+
// are we done
if not_ready {
return Ok(Async::NotReady)
