Created
August 19, 2011 13:47
-
-
Save davidgrenier/1156831 to your computer and use it in GitHub Desktop.
Erlang Ring Problem in F# + Rx
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
#r @"System.Reactive.dll" | |
open System | |
open System.Reactive.Subjects | |
open System.Reactive.Linq | |
let run n m = | |
let now = DateTime.Now | |
let nodes = List.init n (fun _ -> new Subject<_>()) | |
nodes.[nodes.Length - 1] | |
.Finally(fun () -> printfn "Completed in %f" (DateTime.Now - now).TotalSeconds) | |
.Start() |> ignore | |
Seq.iter2 (fun l r -> (l :> IObservable<_>).Subscribe(r) |> ignore) nodes nodes.Tail | |
Seq.init m id |> Seq.iter nodes.Head.OnNext | |
nodes.Head.OnCompleted();; | |
run 100 100000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment