1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

Merge pull request #8 from Turbo87/backoff

Improve `ExponentialBackoff` handling
This commit is contained in:
Tobias Bieniek 2018-06-07 18:07:49 +02:00 committed by GitHub
commit 43396ab3e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,10 +37,13 @@ impl RedisActor {
pub fn start<S: Into<String>>(addr: S) -> Addr<Unsync, RedisActor> { pub fn start<S: Into<String>>(addr: S) -> Addr<Unsync, RedisActor> {
let addr = addr.into(); let addr = addr.into();
let mut backoff = ExponentialBackoff::default();
backoff.max_elapsed_time = None;
Supervisor::start(|_| RedisActor { Supervisor::start(|_| RedisActor {
addr: addr, addr: addr,
cell: None, cell: None,
backoff: ExponentialBackoff::default(), backoff: backoff,
queue: VecDeque::new(), queue: VecDeque::new(),
}) })
} }
@ -74,8 +77,6 @@ impl Actor for RedisActor {
// we stop current context, supervisor will restart it. // we stop current context, supervisor will restart it.
if let Some(timeout) = act.backoff.next_backoff() { if let Some(timeout) = act.backoff.next_backoff() {
ctx.run_later(timeout, |_, ctx| ctx.stop()); ctx.run_later(timeout, |_, ctx| ctx.stop());
} else {
ctx.stop();
} }
} }
}) })
@ -85,8 +86,6 @@ impl Actor for RedisActor {
// we stop current context, supervisor will restart it. // we stop current context, supervisor will restart it.
if let Some(timeout) = act.backoff.next_backoff() { if let Some(timeout) = act.backoff.next_backoff() {
ctx.run_later(timeout, |_, ctx| ctx.stop()); ctx.run_later(timeout, |_, ctx| ctx.stop());
} else {
ctx.stop();
} }
}) })
.wait(ctx); .wait(ctx);