Skip to content

Commit

Permalink
refactor(async_retrier): simplify coroutine wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Dec 30, 2016
1 parent 39cad3b commit 2132bc0
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions riprova/async_retrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@
from paco import TimeoutLimit # noqa


def corowrap(fn):
"""
Wraps a given function as a coroutine.
Arguments:
fn (function|coroutinefunction)
Returns:
coroutinefunction
"""
return asyncio.coroutine(fn)


class AsyncRetrier(Retrier):
"""
AsyncRetrier implements an asynchronous corutine based operation retrier.
Expand Down Expand Up @@ -134,13 +121,13 @@ def __init__(self,
# Maximum optional timeout in miliseconds. Use 0 for no limit
self.timeout = timeout or 0
# Stores optional evaluator function
self.evaluator = corowrap(evaluator) if evaluator else None
self.evaluator = asyncio.coroutine(evaluator) if evaluator else None
# Stores the error evaluator function.
self.error_evaluator = error_evaluator or self.is_whitelisted_error
# Stores optional coroutine function to call on before very
# retry operation. `on_retry` function accepts 2 arguments:
# `err, next_try` and should return nothing.
self.on_retry = corowrap(on_retry) if on_retry else None
self.on_retry = asyncio.coroutine(on_retry) if on_retry else None
# Backoff strategy to use. Defaults to `riprova.ConstantBackoff`.
self.backoff = backoff or ConstantBackoff()
# Function used to sleep. Defaults `asyncio.sleep()`.
Expand Down

0 comments on commit 2132bc0

Please sign in to comment.