Created
October 11, 2015 18:00
-
-
Save bobbychopra/0e2679bc4a213d16179b 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
module Program | |
open System | |
open Akka | |
open Akka.Actor | |
open Akka.FSharp | |
open Akka.Configuration | |
let writer (mailbox:Actor<_>) = | |
let (|Exit|Cont|Toggle|) (str:string) = | |
match str.ToLower() with | |
| "exit" -> Exit | |
| "t" -> Toggle | |
| _ -> Cont | |
let rec loop () = | |
actor{ | |
let! msg = mailbox.Receive () | |
match msg with | |
| Exit -> mailbox.Context.System.Shutdown () | |
| Toggle -> return! pause () | |
| _ -> | |
printfn "%s %s" (DateTime.Now.ToLongTimeString()) msg | |
return! loop () | |
} | |
and pause () = | |
actor { | |
let! msg = mailbox.Receive () | |
match msg with | |
| Exit -> mailbox.Context.System.Shutdown () | |
| Toggle -> | |
mailbox.UnstashAll() | |
return! loop () | |
| m -> | |
mailbox.Stash() | |
return! pause () | |
} | |
loop () | |
type Message = | |
| Subscribe | |
| Unsubscribe | |
| Msg of IActorRef * string | |
[<EntryPoint>] | |
let main argv = | |
let actorSystem = System.create "myActorSystem" (Configuration.load ()) | |
let mywriter = spawn actorSystem "writer" writer | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(0.5), mywriter, "ready....") | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(1.), mywriter, "ready1....") | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(1.1), mywriter, "t") | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(1.2), mywriter, "ready2....") | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(1.3), mywriter, "another ready2....") | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(6.1), mywriter, "t") | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(6.2), mywriter, "ready3....") | |
actorSystem.Scheduler.ScheduleTellOnce (TimeSpan.FromSeconds(6.3), mywriter, "exit") | |
Console.ReadLine () |> ignore | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment