This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def retry(noTimes: Int)(block: ⇒Future[T]): Future[T] = { | |
| val ns: Iterator[Int] = (1 to noTimes).iterator | |
| val attempts: Iterator[Future[T]] = ns.map(_⇒ ()⇒block) | |
| val failed = Future.failed(new Exception) | |
| attempts.foldLeft(failed) | |
| ((a,block) ⇒ a recoverWith { block() }) | |
| } | |
| retry(3) { block } | |
| = unfolds to |