Implement graceful shutdown for wakunode2 and chat2 (#490)

* Implement graceful shutdown

* Consistent use of QuitSuccess
This commit is contained in:
Hanno Cornelius
2021-04-15 10:18:14 +02:00
committed by GitHub
parent 17cfc32c4f
commit 900d53f9df
3 changed files with 34 additions and 11 deletions
+7 -8
View File
@@ -30,6 +30,7 @@ const Help = """
help: Prints this help
connect: dials a remote peer
nick: change nickname for current chat session
exit: exits chat session
"""
const
@@ -203,14 +204,11 @@ proc writeAndPrint(c: Chat) {.async.} =
c.nick = await readNick(c.transp)
echo "You are now known as " & c.nick
# elif line.startsWith("/exit"):
# if p.connected and p.conn.closed.not:
# await p.conn.close()
# p.connected = false
#
# await p.switch.stop()
# echo "quitting..."
# quit(0)
elif line.startsWith("/exit"):
await c.node.stop()
echo "quitting..."
quit(QuitSuccess)
else:
# XXX connected state problematic
if c.started:
@@ -368,6 +366,7 @@ proc processInput(rfd: AsyncFD, rng: ref BrHmacDrbgContext) {.async.} =
node.subscribe(topic, handler)
await chat.readWriteLoop()
runForever()
#await allFuturesThrowing(libp2pFuts)