mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
Add example of sending from ext context
This commit is contained in:
parent
c19738c0d8
commit
f9ed0cbb8c
@ -1,6 +1,7 @@
|
||||
import
|
||||
chronicles,
|
||||
chronos
|
||||
chronos,
|
||||
strformat
|
||||
|
||||
import
|
||||
waku_client
|
||||
@ -10,11 +11,19 @@ proc handleMessages(pubsubTopic: string, message: seq[byte]): Future[
|
||||
void] {.gcsafe, raises: [Defect].} =
|
||||
info "ClientRecv", pubTopic = pubsubTopic, msg = message
|
||||
|
||||
proc demoSendLoop(client: WakuClient): Future[void] {.async.} =
|
||||
for i in 1..10:
|
||||
await sleepAsync(20.seconds)
|
||||
discard client.sendMessage(&"Message:{i}")
|
||||
|
||||
proc main(): Future[void] {.async.} =
|
||||
echo "Starting POC"
|
||||
let cfg = DefaultConfig()
|
||||
let client = initWakuClient(cfg, @[PayloadHandler(handleMessages)])
|
||||
await client.start()
|
||||
asyncSpawn client.start()
|
||||
|
||||
await demoSendLoop(client)
|
||||
|
||||
echo "End of POC"
|
||||
|
||||
when isMainModule:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user