Last active
June 17, 2019 15:33
-
-
Save isaacabraham/ce0ff04b4c489952bc08fc56976324fb 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
open System.Threading.Tasks | |
let add a b = a + b | |
let generateAString() = "foo" | |
let oldMain argv = | |
let anInt = add 1 2 | |
let aString = generateAString() | |
printfn "Number is %d and string is '%s'" anInt aString | |
0 |
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
open System.Threading.Tasks | |
open FSharp.Control.Tasks | |
let addAsync a b = Task.FromResult (a + b) | |
let generateAStringAsync() = Task.FromResult "foo" | |
[<EntryPoint>] | |
let main argv = | |
async { | |
let! anInt = addAsync 1 2 |> Async.AwaitTask | |
let! aString = generateAStringAsync() |> Async.AwaitTask | |
printfn "Number is %d and string is '%s'" anInt aString | |
return 0 | |
} |> Async.RunSynchronously |
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
// Need to add <PackageReference Include="TaskBuilder.fs" Version="2.1.0" /> | |
open System.Threading.Tasks | |
open FSharp.Control.Tasks | |
let addAsync a b = Task.FromResult (a + b) | |
let generateAStringAsync() = Task.FromResult "foo" | |
[<EntryPoint>] | |
let main argv = | |
task { | |
let! anInt = addAsync 1 2 | |
let! aString = generateAStringAsync() | |
printfn "Number is %d and string is '%s'" anInt aString | |
return 0 | |
} |> fun t -> t.Result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment