From c0e73c727561879e6ace130b356db92b2af1a572 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 11 Oct 2017 19:20:05 -0700 Subject: [PATCH] provide wait method --- src/context.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index 0f726312..2941d71c 100644 --- a/src/context.rs +++ b/src/context.rs @@ -4,7 +4,7 @@ use std::collections::VecDeque; use futures::{Async, Stream, Poll}; use bytes::Bytes; -use actix::{Actor, ActorState, ActorContext, AsyncActorContext}; +use actix::{Actor, ActorState, ActorContext, AsyncContext}; use actix::fut::ActorFuture; use actix::dev::{AsyncContextApi, ActorAddressCell, ActorItemsCell, SpawnHandle}; @@ -20,6 +20,7 @@ pub struct HttpContext where A: Actor> + Route, items: ActorItemsCell, address: ActorAddressCell, stream: VecDeque, + wait: Option>>, app_state: Rc<::State>, } @@ -47,7 +48,7 @@ impl ActorContext for HttpContext where A: Actor + Route } } -impl AsyncActorContext for HttpContext where A: Actor + Route +impl AsyncContext for HttpContext where A: Actor + Route { fn spawn(&mut self, fut: F) -> SpawnHandle where F: ActorFuture + 'static @@ -55,6 +56,12 @@ impl AsyncActorContext for HttpContext where A: Actor + R self.items.spawn(fut) } + fn wait(&mut self, fut: F) + where F: ActorFuture + 'static + { + self.wait = Some(Box::new(fut)); + } + fn cancel_future(&mut self, handle: SpawnHandle) -> bool { self.items.cancel_future(handle) } @@ -77,6 +84,7 @@ impl HttpContext where A: Actor + Route { items: ActorItemsCell::default(), address: ActorAddressCell::default(), stream: VecDeque::new(), + wait: None, app_state: state, } } @@ -139,6 +147,19 @@ impl Stream for HttpContext where A: Actor + Route _ => () } + // check wait future + if self.wait.is_some() && self.act.is_some() { + if let Some(ref mut act) = self.act { + if let Some(ref mut fut) = self.wait { + match fut.poll(act, ctx) { + Ok(Async::NotReady) => return Ok(Async::NotReady), + _ => (), + } + } + } + self.wait = None; + } + let mut prep_stop = false; loop { let mut not_ready = true;