diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-11-25 21:26:34 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-11-25 21:50:37 +0100 |
| commit | e1bd06830bff408735c66a5ec02935d20dda6b60 (patch) | |
| tree | 31635b1b27dbdcbdc5be987c7f44df10841a3f69 | |
| parent | 68c7fca4d0e6f4c033bb5b980ca4b464f0c75260 (diff) | |
| download | chawan-e1bd06830bff408735c66a5ec02935d20dda6b60.tar.gz | |
client: exit if quit was called inside a job
ref. https://todo.sr.ht/~bptato/chawan/27
| -rw-r--r-- | src/local/client.nim | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/local/client.nim b/src/local/client.nim index 3bef5c75..1669898c 100644 --- a/src/local/client.nim +++ b/src/local/client.nim @@ -93,14 +93,6 @@ proc interruptHandler(rt: JSRuntime; opaque: pointer): cint {.cdecl.} = discard return 0 -proc runJSJobs(client: Client) = - while true: - let r = client.jsrt.runJSJobs() - if r.isSome: - break - let ctx = r.error - ctx.writeException(client.console.err) - proc cleanup(client: Client) = if client.alive: client.alive = false @@ -118,6 +110,16 @@ proc quit(client: Client; code = 0) = client.cleanup() quit(code) +proc runJSJobs(client: Client) = + while true: + let r = client.jsrt.runJSJobs() + if r.isSome: + break + let ctx = r.error + ctx.writeException(client.console.err) + if client.exitCode != -1: + client.quit(0) + proc evalJS(client: Client; src, filename: string; module = false): JSValue = client.pager.term.unblockStdin() let flags = if module: @@ -426,8 +428,7 @@ proc input(client: Client): EmptyPromise = client.feednext = false client.pager.inputBuffer = "" if p == nil: - p = EmptyPromise() - p.resolve() + p = newResolvedPromise() return p proc consoleBuffer(client: Client): Container {.jsfget.} = |