Created
June 13, 2019 15:26
-
-
Save vshapenko/e991848272cb8ec3805b6191daff3149 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
module Channel= | |
type Msg= | |
|Add of string | |
|AddSub of Event<string> | |
let messages=new List<string>() | |
let inbox=MailboxProcessor.Start (fun b-> | |
let rec loop state= | |
async{ | |
let! msg=b.Receive() | |
match msg with | |
|Add str-> match state with | |
|[]->messages.Add str | |
|x->x|>Seq.iter(fun (x:Event<string>)->x.Trigger str) | |
|AddSub evt-> | |
let newState=evt::state | |
messages|>Seq.iter (fun s->newState|>Seq.iter(fun x->x.Trigger s)) | |
messages.Clear() | |
return! loop newState | |
} | |
loop List.empty | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment