From b28f32e82c116a73ad3c3be8595ce5bd677ac187 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 11 Dec 2019 20:23:14 +0600 Subject: [PATCH] Allow to create framed::Dispatcher with custom mpsc::Receiver --- actix-utils/CHANGES.md | 4 ++++ actix-utils/Cargo.toml | 2 +- actix-utils/src/framed.rs | 26 ++++++++++++++++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index ee8fc50b..3cc98d96 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [1.0.2] - 2019-12-11 + +* Allow to create `framed::Dispatcher` with custom `mpsc::Receiver` + ## [1.0.1] - 2019-12-11 * Optimize InOrder service diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index 9539733e..b1654fbc 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-utils" -version = "1.0.1" +version = "1.0.2" authors = ["Nikolay Kim "] description = "Actix utils - various actix net related services" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-utils/src/framed.rs b/actix-utils/src/framed.rs index dfa572e3..1bdd364f 100644 --- a/actix-utils/src/framed.rs +++ b/actix-utils/src/framed.rs @@ -127,30 +127,44 @@ where } } + /// Construct new `Dispatcher` instance with customer `mpsc::Receiver` + pub fn with_rx>( + framed: Framed, + service: F, + rx: mpsc::Receiver::Item>, S::Error>>, + ) -> Self { + let tx = rx.sender(); + Dispatcher { + framed, + rx, + tx, + service: service.into_service(), + state: State::Processing, + } + } + /// Get sink pub fn get_sink(&self) -> mpsc::Sender::Item>, S::Error>> { self.tx.clone() } - /// Get reference to a service wrapped by `FramedTransport` instance. + /// Get reference to a service wrapped by `Dispatcher` instance. pub fn get_ref(&self) -> &S { &self.service } - /// Get mutable reference to a service wrapped by `FramedTransport` - /// instance. + /// Get mutable reference to a service wrapped by `Dispatcher` instance. pub fn get_mut(&mut self) -> &mut S { &mut self.service } - /// Get reference to a framed instance wrapped by `FramedTransport` + /// Get reference to a framed instance wrapped by `Dispatcher` /// instance. pub fn get_framed(&self) -> &Framed { &self.framed } - /// Get mutable reference to a framed instance wrapped by `FramedTransport` - /// instance. + /// Get mutable reference to a framed instance wrapped by `Dispatcher` instance. pub fn get_framed_mut(&mut self) -> &mut Framed { &mut self.framed }