Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Last active February 27, 2021 13:39
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 gsscoder/6e2b49af9beb1699a5291f6539a88b8a to your computer and use it in GitHub Desktop.
Save gsscoder/6e2b49af9beb1699a5291f6539a88b8a to your computer and use it in GitHub Desktop.
Simple F# function that may inject chaos
// 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