Skip to content

Instantly share code, notes, and snippets.

@natalie-o-perret
Created April 17, 2020 13:14
Show Gist options
  • Save natalie-o-perret/3e0ceea01a994531914e5260f1521f95 to your computer and use it in GitHub Desktop.
Save natalie-o-perret/3e0ceea01a994531914e5260f1521f95 to your computer and use it in GitHub Desktop.
Hot / Cold asynchrony
open System.Threading.Tasks
open FSharp.Control.Tasks.V2.ContextInsensitive
let aTask = task {
do! Task.Delay(1000)
printfn "I'm in aTask"
}
let anAsync = async {
do! Task.Delay(1000) |> Async.AwaitTask
printfn "I'm in anAsync"
}
let runTaskSync t =
t |> Async.AwaitTask |> Async.RunSynchronously
let runAsyncSync a =
a |> Async.RunSynchronously
[<EntryPoint>]
let main _ =
runTaskSync aTask
runTaskSync aTask
runAsyncSync anAsync
runAsyncSync anAsync
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment