Last active
September 23, 2021 19:34
-
-
Save isaacabraham/f157f0c64cfdc662e0a83fc0ff3ed84b 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 | |
/// Asynchronously loads some data from the DB | |
let fetchDataFromDb () = async { | |
printfn "Loading DB data..." | |
return 99 | |
} | |
let random = Random() | |
/// Asynchronously loads some data from the network | |
let fetchDataFromNetwork () = async { | |
printfn "Fetching data from network..." | |
return random.Next 10 | |
} | |
/// Asynchronously creates a function to fetch data from the network, and adds it to the *cached* DB value. | |
let createFetchFromNetwork () = async { | |
let! dbValue = fetchDataFromDb () | |
return async { | |
let! networkValue = fetchDataFromNetwork () | |
return networkValue + dbValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment