Last active
February 27, 2021 13:39
-
-
Save gsscoder/6e2b49af9beb1699a5291f6539a88b8a to your computer and use it in GitHub Desktop.
Simple F# function that may inject chaos
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
// inspired by https://www.youtube.com/watch?v=RWyZkNzvC-c&t=553s | |
// $ dotnet fsi chaos.fsx | |
// latency test | |
// 0.919409 | |
open System | |
open System.Threading | |
let chaos (name:string) (shouldChaos:unit -> bool) (chaos:unit -> unit) (service:unit -> 't) = | |
if shouldChaos () then | |
printfn "%s" name | |
do chaos | |
else () | |
service () | |
let always = fun () -> true | |
let latency = fun () -> Thread.Sleep(3000) | |
let computeRandom = fun () -> (new Random()).NextDouble() | |
let result = chaos "latency test" always latency computeRandom | |
printfn "%f" result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment