Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active September 23, 2021 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacabraham/f157f0c64cfdc662e0a83fc0ff3ed84b to your computer and use it in GitHub Desktop.
Save isaacabraham/f157f0c64cfdc662e0a83fc0ff3ed84b to your computer and use it in GitHub Desktop.
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