Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc processHost(host: string, port: Port) {.async.} = # template/generic instantiation from here
- let sock = newAsyncSocket()
- await sock.connect(host, port)
- asyncCheck sock.process(host) # Error goes away when I remove this call
- proc process(peer: RemoteRuntime, remote: string) {.async.} =
- while true:
- let str = await peer.recvLine()
- if str == "": break
- let msg = to[Message](str)
- case (to[Message](str)).typ:
- of tokenMsg: asyncCheck processToken(msg.token)
- of hostMsg: asyncCheck processHost(msg.host, msg.port)
- of stopMsg: quit(0) # TODO: Shut down more gracefully
- proc listenForPeers(port: Port) {.async.} =
- let listener = newAsyncSocket()
- listener.bindAddr(port)
- listener.listen()
- while true:
- let (host, peer) = await listener.acceptAddr()
- asyncCheck peer.process(host)
- peers.add(peer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement