Ivan Folgueira Bande 069c1ad2a5
refactor(cbindings): libwaku - run waku node in a secondary working thread (#1865)
* Refactoring to have a working waku_thread
2023-07-31 09:52:04 +02:00

38 lines
676 B
Nim

import
std/options
import
chronos,
stew/results,
stew/shims/net
import
../../../waku/v2/node/waku_node,
./request
type
NodeLifecycleMsgType* = enum
START_NODE
STOP_NODE
type
NodeLifecycleRequest* = ref object of InterThreadRequest
operation: NodeLifecycleMsgType
proc new*(T: type NodeLifecycleRequest,
op: NodeLifecycleMsgType): T =
return NodeLifecycleRequest(operation: op)
method process*(self: NodeLifecycleRequest,
node: WakuNode): Future[Result[string, string]] {.async.} =
case self.operation:
of START_NODE:
waitFor node.start()
of STOP_NODE:
waitFor node.stop()
return ok("")