5 people like it.

Async function that retries work

A simple asynchronous workflow that retries running a given async workflow (until "resultOk" function returns true or until a specified number of retries is performed). The function uses tail-recursion in async workflows.

let rec retry work resultOk retries = async {
  let! res = work
  if (resultOk res) || (retries = 0) then return res
  else return! retry work resultOk (retries - 1) }
val retry : work:Async<'a> -> resultOk:('a -> bool) -> retries:int -> Async<'a>

Full name: Script.retry
val work : Async<'a>
val resultOk : ('a -> bool)
val retries : int
val async : AsyncBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.async
val res : 'a
Raw view New version

More information

Posted:4 years ago
Author:Tomas Petricek
Tags: async , tail-recursion , retry