Skip to content

Instantly share code, notes, and snippets.

@vshapenko
Created June 13, 2019 15:26
Show Gist options
  • Save vshapenko/e991848272cb8ec3805b6191daff3149 to your computer and use it in GitHub Desktop.
Save vshapenko/e991848272cb8ec3805b6191daff3149 to your computer and use it in GitHub Desktop.
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