Skip to content

Commit

Permalink
Added onRestartFailed callback for async process
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Aug 18, 2024
1 parent 7853f6e commit ae86865
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/misc/async_process.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type AsyncProcess* = ref object
name: string
args: seq[string]
onRestarted*: proc(): Future[void] {.gcsafe.}
onRestartFailed*: proc(): Future[void] {.gcsafe.}
dontRestart: bool
process: Process
input: AsyncChannel[char]
Expand All @@ -26,7 +27,7 @@ type AsyncProcess* = ref object
writerFlowVar: FlowVarBase

proc isAlive*(process: AsyncProcess): bool =
return process.process.running
return process.process.isNotNil and process.process.running

proc newAsyncChannel*[T](): AsyncChannel[T] =
new result
Expand Down Expand Up @@ -346,12 +347,15 @@ proc restartServer(process: AsyncProcess) {.async, gcsafe.} =
inc startCounter

if not process.start():
if process.onRestartFailed.isNotNil:
process.onRestartFailed().await
break

startCounter = 0

if not process.onRestarted.isNil:
process.onRestarted().await


proc startAsyncProcess*(name: string, args: seq[string] = @[], autoRestart = true, autoStart = true): AsyncProcess {.gcsafe.} =
let process = AsyncProcess()
process.name = name
Expand Down

0 comments on commit ae86865

Please sign in to comment.