Created
August 21, 2013 13:54
-
-
Save isaacabraham/6294739 to your computer and use it in GitHub Desktop.
This file contains 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
let createAgent() = | |
let tokenSource = new System.Threading.CancellationTokenSource() | |
Agent.Start((fun inbox -> async { | |
printfn "spun up a new agent..." | |
while true do | |
let! data = inbox.Receive() | |
let! result = // Do some async work here... | |
match result with | |
// Everything done, we can cancel | |
| AllDone -> printfn "completed!" | |
tokenSource.Cancel() | |
// More to do here, wait a bit and then try again | |
| MoreToDo -> printfn "retrying in a bit..." | |
do! Async.Sleep 2500 | |
inbox.Post data }), tokenSource.Token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment