1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

Allow user to provide addr to custom resolver

We basically swaps Addr with Recipient to enable user to use custom resolver
This commit is contained in:
Douman 2018-11-22 19:20:07 +03:00
parent 389cb13cd6
commit 9aab382ea8
3 changed files with 10 additions and 6 deletions

View File

@ -4,6 +4,8 @@
## Changed ## Changed
* `ClientConnector::resolver` now accepts `Into<Recipient>` instead of `Addr`. It enables user to implement own resolver.
* `QueryConfig` and `PathConfig` are made public. * `QueryConfig` and `PathConfig` are made public.
## [0.7.14] - 2018-11-14 ## [0.7.14] - 2018-11-14

View File

@ -61,7 +61,7 @@ flate2-rust = ["flate2/rust_backend"]
cell = ["actix-net/cell"] cell = ["actix-net/cell"]
[dependencies] [dependencies]
actix = "0.7.6" actix = "0.7.7"
actix-net = "0.2.2" actix-net = "0.2.2"
askama_escape = "0.1.0" askama_escape = "0.1.0"

View File

@ -5,7 +5,7 @@ use std::{fmt, io, mem, time};
use actix::resolver::{Connect as ResolveConnect, Resolver, ResolverError}; use actix::resolver::{Connect as ResolveConnect, Resolver, ResolverError};
use actix::{ use actix::{
fut, Actor, ActorFuture, ActorResponse, Addr, AsyncContext, Context, fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context,
ContextFutureSpawner, Handler, Message, Recipient, StreamHandler, Supervised, ContextFutureSpawner, Handler, Message, Recipient, StreamHandler, Supervised,
SystemService, WrapFuture, SystemService, WrapFuture,
}; };
@ -220,7 +220,7 @@ pub struct ClientConnector {
acq_tx: mpsc::UnboundedSender<AcquiredConnOperation>, acq_tx: mpsc::UnboundedSender<AcquiredConnOperation>,
acq_rx: Option<mpsc::UnboundedReceiver<AcquiredConnOperation>>, acq_rx: Option<mpsc::UnboundedReceiver<AcquiredConnOperation>>,
resolver: Option<Addr<Resolver>>, resolver: Option<Recipient<ResolveConnect>>,
conn_lifetime: Duration, conn_lifetime: Duration,
conn_keep_alive: Duration, conn_keep_alive: Duration,
limit: usize, limit: usize,
@ -239,7 +239,7 @@ impl Actor for ClientConnector {
fn started(&mut self, ctx: &mut Self::Context) { fn started(&mut self, ctx: &mut Self::Context) {
if self.resolver.is_none() { if self.resolver.is_none() {
self.resolver = Some(Resolver::from_registry()) self.resolver = Some(Resolver::from_registry().recipient())
} }
self.collect_periodic(ctx); self.collect_periodic(ctx);
ctx.add_stream(self.acq_rx.take().unwrap()); ctx.add_stream(self.acq_rx.take().unwrap());
@ -503,8 +503,10 @@ impl ClientConnector {
} }
/// Use custom resolver actor /// Use custom resolver actor
pub fn resolver(mut self, addr: Addr<Resolver>) -> Self { ///
self.resolver = Some(addr); /// By default actix's Resolver is used.
pub fn resolver<A: Into<Recipient<ResolveConnect>>>(mut self, addr: A) -> Self {
self.resolver = Some(addr.into());
self self
} }