Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save panesofglass/7998ea637e5662487bdb to your computer and use it in GitHub Desktop.

Select an option

Save panesofglass/7998ea637e5662487bdb to your computer and use it in GitHub Desktop.
type SampleResourceMethod =
| Create of AsyncReplyChannel<unit>
| SetTimestamp of DateTimeOffset * AsyncReplyChannel<unit>
type SampleResource() =
let agent = MailboxProcessor<_>.Start(fun inbox ->
let rec loop () = async {
let! msg = inbox.Receive()
match msg with
| Create ch ->
// ...
ch.Reply()
return! loop()
| SetTimestamp (dt, ch) ->
// ...
ch.Reply()
return! loop() }
loop())
member x.Create(): Async<unit> =
agent.PostAndAsyncReply (fun ch -> Create ch)
member x.SetTimestamp(dt: DateTimeOffset): Async<unit> =
agent.PostAndAsyncReply (fun ch -> SetTimestamp(dt, ch))
/// Generic Send, similar to Ruby's send method.
member x.Send(msg: SampleResourceMethod) =
agent.PostAndAsyncReply msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment