From f24c866a30423d5feb6412e6548fad78653fb10e Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sat, 24 Aug 2019 13:15:45 -0600 Subject: [PATCH] use loop on closed flag --- libp2p/multistreamselect.nim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libp2p/multistreamselect.nim b/libp2p/multistreamselect.nim index 13dba5f79..0d2ebf7eb 100644 --- a/libp2p/multistreamselect.nim +++ b/libp2p/multistreamselect.nim @@ -64,7 +64,7 @@ proc handle*(m: MultisteamSelect, conn: Connection) {.async.} = if not (await m.select(conn)): return - block handleLoop: + while not conn.closed: var ms = cast[string](await conn.readLp()) ms.removeSuffix("\n") if ms.len() <= 0: @@ -73,16 +73,14 @@ proc handle*(m: MultisteamSelect, conn: Connection) {.async.} = case ms: of "ls": for h in m.handlers: - await conn.writeLp(h.proto) - break handleLoop + await conn.writeLp(h.proto & "\n") else: for h in m.handlers: if (not isNil(h.match) and h.match(ms)) or ms == h.proto: await h.handler(conn, ms) - break + return else: await conn.write(Na) - break handleLoop proc addHandler*(m: MultisteamSelect, proto: string,