From ae868650ed8385aaf9a8aabf46d1d7efc0e6e702 Mon Sep 17 00:00:00 2001 From: Nimaoth Date: Sun, 18 Aug 2024 17:04:16 +0200 Subject: [PATCH] Added onRestartFailed callback for async process --- src/misc/async_process.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/misc/async_process.nim b/src/misc/async_process.nim index 9f337e75..5f9b00a5 100644 --- a/src/misc/async_process.nim +++ b/src/misc/async_process.nim @@ -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] @@ -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 @@ -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