Skip to content

Instantly share code, notes, and snippets.

@dustinlacewell-wk
Created December 7, 2017 05:21
Show Gist options
  • Save dustinlacewell-wk/54c7591fde643d12e5d7bb0571decfd1 to your computer and use it in GitHub Desktop.
Save dustinlacewell-wk/54c7591fde643d12e5d7bb0571decfd1 to your computer and use it in GitHub Desktop.
let cell (x: 'a) : Job<Cell<'a>> = job {
let c = {reqCh = Ch (); replyCh = Ch ()}
let rec server x = job {
let! req = Ch.take c.reqCh
match req with
| Get ->
do! Ch.give c.replyCh x
return! server x
| Put x ->
return! server x
}
do! Job.start (server x)
return c
}
let create (x: 'a) : Job<Cell<'a>> = Job.delay <| fun () ->
let c = {reqCh = Ch (); replyCh = Ch ()}
let rec server x =
Ch.take c.reqCh >>= function
| Get ->
Ch.give c.replyCh x >>=. server x
| Put x -> server x
Job.start (server x) >>-. c
let create x = Job.delay <| fun () ->
let c = {reqCh = Ch (); replyCh = Ch ()}
Job.iterateServer x <| fun x ->
c.reqCh >>= function
| Get -> c.replyCh *<- x >>-. x
| Put x -> Job.result x
>>-. c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment