Node API: Implement basic subscribe topic (#89)

* Fix init signature according to Node API

See https://github.com/status-im/nim-waku/blob/master/docs/api/v2/node.md

* Update docs and example

* Node API: Basic subscribe

* Modify example with subscribe handler
This commit is contained in:
Oskar Thorén
2020-07-28 16:17:50 +08:00
committed by GitHub
parent 1ca3962e8d
commit ad5d5e2401
2 changed files with 26 additions and 13 deletions
+10 -7
View File
@@ -15,15 +15,18 @@ import ../../waku/node/v2/wakunode2
# Loads the config in `waku/node/v2/config.nim`
let conf = WakuNodeConf.load()
# Create and start the node
#proc runBackground(conf: WakuNodeConf) {.async.} =
# init(conf)
# runForever()
# Node operations happens asynchronously
proc runBackground(conf: WakuNodeConf) {.async.} =
# Create and start the node
let node = await init(conf)
discard init(conf)
echo("Do stuff after with node")
# Subscribe to a topic
let topic = "foobar"
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
info "Hit subscribe handler", topic=topic, data=data
node.subscribe(topic, handler)
discard runBackground(conf)
runForever()
# TODO Lets start with Nim Node API first