Add test_simpleChatProtocol
This commit is contained in:
parent
e26c718142
commit
947e560fb7
|
@ -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()
|
Loading…
Reference in New Issue