Skip to content

Commit f9ed0cb

Browse files
committed
Add example of sending from ext context
1 parent c19738c commit f9ed0cb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/nim_chat_poc.nim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import
22
chronicles,
3-
chronos
3+
chronos,
4+
strformat
45

56
import
67
waku_client
@@ -10,11 +11,19 @@ proc handleMessages(pubsubTopic: string, message: seq[byte]): Future[
1011
void] {.gcsafe, raises: [Defect].} =
1112
info "ClientRecv", pubTopic = pubsubTopic, msg = message
1213

14+
proc demoSendLoop(client: WakuClient): Future[void] {.async.} =
15+
for i in 1..10:
16+
await sleepAsync(20.seconds)
17+
discard client.sendMessage(&"Message:{i}")
18+
1319
proc main(): Future[void] {.async.} =
1420
echo "Starting POC"
1521
let cfg = DefaultConfig()
1622
let client = initWakuClient(cfg, @[PayloadHandler(handleMessages)])
17-
await client.start()
23+
asyncSpawn client.start()
24+
25+
await demoSendLoop(client)
26+
1827
echo "End of POC"
1928

2029
when isMainModule:

0 commit comments

Comments
 (0)