1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-01-18 20:01:48 +01:00

optimize InOrder service

This commit is contained in:
Nikolay Kim 2019-12-11 18:55:53 +06:00
parent c7a8743bf9
commit 8bb81c0768
3 changed files with 5 additions and 10 deletions

View File

@ -1,5 +1,9 @@
# Changes
## [1.0.1] - 2019-12-11
* Optimize InOrder service
## [1.0.0] - 2019-12-11
* Simplify oneshot and mpsc implementations

View File

@ -1,6 +1,6 @@
[package]
name = "actix-utils"
version = "1.0.0"
version = "1.0.1"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix utils - various actix net related services"
keywords = ["network", "framework", "async", "futures"]

View File

@ -4,14 +4,12 @@ use std::fmt;
use std::future::Future;
use std::marker::PhantomData;
use std::pin::Pin;
use std::rc::Rc;
use std::task::{Context, Poll};
use actix_service::{IntoService, Service, Transform};
use futures::future::{ok, Ready};
use crate::oneshot;
use crate::task::LocalWaker;
struct Record<I, E> {
rx: oneshot::Receiver<Result<I, E>>,
@ -105,7 +103,6 @@ where
pub struct InOrderService<S: Service> {
service: S,
task: Rc<LocalWaker>,
acks: VecDeque<Record<S::Response, S::Error>>,
}
@ -123,7 +120,6 @@ where
Self {
service: service.into_service(),
acks: VecDeque::new(),
task: Rc::new(LocalWaker::new()),
}
}
}
@ -141,9 +137,6 @@ where
type Future = InOrderServiceResponse<S>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
// poll_ready could be called from different task
self.task.register(cx.waker());
// check acks
while !self.acks.is_empty() {
let rec = self.acks.front_mut().unwrap();
@ -172,11 +165,9 @@ where
let (tx2, rx2) = oneshot::channel();
self.acks.push_back(Record { rx: rx1, tx: tx2 });
let task = self.task.clone();
let fut = self.service.call(request);
actix_rt::spawn(async move {
let res = fut.await;
task.wake();
let _ = tx1.send(res);
});