diff --git a/docs/fsharp/tutorials/asynchronous-and-concurrent-programming/async.md b/docs/fsharp/tutorials/asynchronous-and-concurrent-programming/async.md index 306e3d3fa3dc1..ee54cd46ce336 100644 --- a/docs/fsharp/tutorials/asynchronous-and-concurrent-programming/async.md +++ b/docs/fsharp/tutorials/asynchronous-and-concurrent-programming/async.md @@ -185,24 +185,23 @@ In contrast, F# async workflows are more naturally cancellable. Cancellation is Example: ```fsharp -open System -open System.Net open System.Threading -let uploadDataAsync url data = +// Create a workflow which will loop forever. +let workflow = async { - let uri = Uri(url) - use webClient = new WebClient() - webClient.UploadStringAsync(uri, data) + while true do + printfn "Working..." + do! Async.Sleep 1000 } + +let tokenSource = new CancellationTokenSource() -let workflow = uploadDataAsync "https://url-to-upload-to.com" "hello, world!" - -let token = new CancellationTokenSource() -Async.Start (workflow, token.Token) +// Start the workflow in the background +Async.Start (workflow, tokenSource.Token) -// Immediately cancel uploadDataAsync after it's been started. -token.Cancel() +// Executing the next line will stop the workflow +tokenSource.Cancel() ``` And that’s it!