Add run and stop

This commit is contained in:
Diego 2022-11-21 10:40:54 +01:00
parent 1e46642c96
commit 06b472d30c
No known key found for this signature in database
GPG Key ID: C9DAC9BF68D1F806
1 changed files with 6 additions and 0 deletions

View File

@ -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 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, proc addConnEventHandler*(s: Switch,
handler: ConnEventHandler, handler: ConnEventHandler,
kind: ConnEventKind) {.public.} = kind: ConnEventKind) {.public.} =
@ -299,6 +301,9 @@ proc stop*(s: Switch) {.async, public.} =
if not a.finished: if not a.finished:
a.cancel() a.cancel()
for service in s.services:
await service.stop(s)
await s.ms.stop() await s.ms.stop()
trace "Switch stopped" trace "Switch stopped"
@ -338,6 +343,7 @@ proc start*(s: Switch) {.async, gcsafe, public.} =
for service in s.services: for service in s.services:
await service.setup(s) await service.setup(s)
await service.run(s)
s.started = true s.started = true