Skip to content

Commit

Permalink
Merge pull request #10 from stacycurl/fix-iterateDelay
Browse files Browse the repository at this point in the history
Fix iterateDelay
  • Loading branch information
adelbertc committed Mar 9, 2015
2 parents ac9f378 + d021682 commit 212533d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/scala/rebind/RetryPolicy.scala
Expand Up @@ -178,7 +178,7 @@ trait RetryPolicyFunctions {

/** Constantly retry, starting at the specified base and iterating */
def iterateDelay(base: FiniteDuration)(f: FiniteDuration => FiniteDuration): RetryPolicy =
RetryPolicy(Function.const(Option(f(base))))
RetryPolicy(n => Option(Stream.iterate(base)(f)(n)))

/** Constantly retry, pausing a fixed amount in between */
def constantDelay(delay: FiniteDuration): RetryPolicy =
Expand Down
9 changes: 9 additions & 0 deletions core/src/test/scala/rebind/RetryPolicySpec.scala
Expand Up @@ -46,6 +46,7 @@ class RetryPolicySpec extends Specification with ScalaCheck with RetryPolicySpec
uses handler ${retryingUsesHandler}
retries until success ${retryingUntilSuccess}
exhausts policy ${retryingExhaustPolicy}
can iterate ${iterateDelay}
"""

def makeFailedAction[E, A](n: Int, error: E, success: A): TestAction[E, A] =
Expand Down Expand Up @@ -223,6 +224,14 @@ class RetryPolicySpec extends Specification with ScalaCheck with RetryPolicySpec

exhaustPolicy(function)
}

def iterateDelay = {
val policy = RetryPolicy.iterateDelay(1.second)(_ * 2)

policy.run(0) mustEqual Some(1.second)
policy.run(1) mustEqual Some(2.seconds)
policy.run(2) mustEqual Some(4.seconds)
}
}

trait RetryPolicySpecInstances extends OrphanInstances {
Expand Down

0 comments on commit 212533d

Please sign in to comment.