Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Created September 12, 2018 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasily-kirichenko/f77cb6cf317039e56ce41d564834e5b5 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/f77cb6cf317039e56ce41d564834e5b5 to your computer and use it in GitHub Desktop.
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