small NimbusState refactoring

This commit is contained in:
Ștefan Talpalaru 2020-05-21 03:33:11 +02:00
parent 47295c7f54
commit cf2a6fb621
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
1 changed files with 8 additions and 10 deletions

View File

@ -27,7 +27,7 @@ const
type type
NimbusState = enum NimbusState = enum
Starting, Running, Stopping, Stopped Starting, Running, Stopping
NimbusNode = ref object NimbusNode = ref object
rpcServer*: RpcHttpServer rpcServer*: RpcHttpServer
@ -36,7 +36,6 @@ type
proc start(nimbus: NimbusNode) = proc start(nimbus: NimbusNode) =
var conf = getConfiguration() var conf = getConfiguration()
nimbus.state = Starting
## logging ## logging
setLogLevel(conf.debug.logLevel) setLogLevel(conf.debug.logLevel)
@ -160,19 +159,18 @@ proc stop*(nimbus: NimbusNode) {.async, gcsafe.} =
nimbus.rpcServer.stop() nimbus.rpcServer.stop()
proc process*(nimbus: NimbusNode) = proc process*(nimbus: NimbusNode) =
if nimbus.state == Running: # Main event loop
# Main loop while nimbus.state == Running:
while nimbus.state == Running: try:
try: poll()
poll() except CatchableError as e:
except CatchableError as e: debug "Exception in poll()", exc = e.name, err = e.msg
debug "Exception in poll()", exc = e.name, err = e.msg
# Stop loop # Stop loop
waitFor nimbus.stop() waitFor nimbus.stop()
when isMainModule: when isMainModule:
var nimbus = NimbusNode() var nimbus = NimbusNode(state: Starting)
## Ctrl+C handling ## Ctrl+C handling
proc controlCHandler() {.noconv.} = proc controlCHandler() {.noconv.} =