Last active
August 29, 2015 14:17
-
-
Save panesofglass/7998ea637e5662487bdb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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