Add test_simpleChatProtocol

This commit is contained in:
Emery Hemingway 2022-12-08 00:30:41 -06:00
parent e26c718142
commit 947e560fb7
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: ☭ 2022 Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/asyncdispatch
import syndicate
import syndicate/protocols/simpleChatProtocol
bootDataspace("main") do (ds: Ref; turn: var Turn):
let me = "user_a"
let h = publish(turn, ds, Present(username: me))
message(turn, ds, Says(who: me, what: "goodbye"))
onPublish(turn, ds, ?Present) do (username: string):
echo "presence of ", username, " asserted"
onMessage(turn, ds, ?Says) do (who: string, what: string):
echo who, " says ", what
retract(turn, h)
echo "retracted something"
during(turn, ds, ?Present) do (username: string):
echo username, " arrived"
retract(turn, h)
do:
echo "someone departed"
quit()
runForever()