From 06b472d30cbda80c535ec4f3ea652d40d63c3427 Mon Sep 17 00:00:00 2001 From: Diego Date: Mon, 21 Nov 2022 10:40:54 +0100 Subject: [PATCH] Add run and stop --- libp2p/switch.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libp2p/switch.nim b/libp2p/switch.nim index 18c3d3ee1..94882b4b5 100644 --- a/libp2p/switch.nim +++ b/libp2p/switch.nim @@ -82,6 +82,8 @@ method setup*(self: Service, switch: Switch) {.base, async, gcsafe, public.} = d method run*(self: Service, switch: Switch) {.base, async, gcsafe, public.} = discard +method stop*(self: Service, switch: Switch) {.base, async, gcsafe, public.} = discard + proc addConnEventHandler*(s: Switch, handler: ConnEventHandler, kind: ConnEventKind) {.public.} = @@ -299,6 +301,9 @@ proc stop*(s: Switch) {.async, public.} = if not a.finished: a.cancel() + for service in s.services: + await service.stop(s) + await s.ms.stop() trace "Switch stopped" @@ -338,6 +343,7 @@ proc start*(s: Switch) {.async, gcsafe, public.} = for service in s.services: await service.setup(s) + await service.run(s) s.started = true