Created
September 12, 2018 07:18
-
-
Save vasily-kirichenko/f77cb6cf317039e56ce41d564834e5b5 to your computer and use it in GitHub Desktop.
This file contains 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
let props (_scanType: ScanType) : Akka.Actor.Props = | |
props( | |
let rec start (ctx: Actor<obj>) (state: State) (msg: obj) = | |
match msg with | |
| LifecycleEvent PostStop -> kill state.Process | |
| :? Msg as msg -> | |
match msg with | |
| Start -> | |
Starter.start def |> Async.map Started |!> ctx.Self.Retype() | |
become (starting ctx state) | |
| _ -> unhandled() | |
| _ -> unhandled() | |
and starting (ctx: Actor<obj>) (state: State) (msg: obj) = | |
match msg with | |
| LifecycleEvent PostStop -> kill state.Process | |
| :? Msg as msg -> | |
match msg with | |
| Started proc -> | |
match proc with | |
| Ok proc -> become (serving ctx { state with Process = Some proc }) | |
| Error _ -> | |
ctx.Schedule (TimeSpan.FromSeconds 1.0) (ctx.Self.Retype()) Start |> ignore | |
become (start ctx state) | |
| _ -> unhandled() | |
| _ -> unhandled() | |
and serving (_ctx: Actor<obj>) (state: State) (msg: obj) = | |
match msg with | |
| LifecycleEvent PostStop -> kill state.Process | |
| :? Msg as msg -> | |
match msg with | |
| Scan _file -> | |
ignored() | |
| _ -> unhandled() | |
| _ -> unhandled() | |
//let lifeCycle (_: Actor<obj>) (state: State) (msg: obj) = | |
// match msg with | |
// | LifecycleEvent PostStop -> kill state.Process | |
// | _ -> unhandled() | |
fun (ctx: Actor<obj>) -> | |
ctx.Self.Retype() <! Start | |
// become (lifeCycle ctx <|> start ctx { Process = None }) | |
become (start ctx { Process = None }) | |
).ToProps() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment