Created
November 24, 2016 12:42
-
-
Save battermann/a1b3e5bf8518868220f2b2195ea7a247 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
#load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs" | |
open System | |
open Chessie.ErrorHandling | |
type Person = { FirstName: string; LastName: string } | |
let id1 = Guid.NewGuid() | |
let id2 = Guid.NewGuid() | |
let getAsync id = | |
let people = | |
[(id1, { FirstName = "Don"; LastName = "Syme" }) | |
(id2, { FirstName = "Martin"; LastName = "Odersky" })] | |
|> Map.ofList | |
let get id: Result<Person, string> = | |
people |> Map.tryFind id |> Trial.failIfNone "not found" | |
get id |> Async.singleton |> AR | |
let eventuallyErrorOrTwoDudes: AsyncResult<Person list, string> = | |
asyncTrial { | |
let! don = getAsync id1 | |
let! martin = getAsync id2 // can this be run in parallel? | |
return [don; martin] } | |
printfn "%A" (getAsync id1 |> Async.ofAsyncResult |> Async.RunSynchronously) | |
printfn "%A" (getAsync (Guid.NewGuid()) |> Async.ofAsyncResult |> Async.RunSynchronously) | |
printfn "%A" (eventuallyErrorOrTwoDudes |> Async.ofAsyncResult |> Async.RunSynchronously) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment