Introduced 'reg' keyword, and changed the await behaviour for custom
procs.
This commit is contained in:
parent
ae64089e53
commit
70d67daa14
2 changed files with 149 additions and 88 deletions
|
|
@ -1,15 +1,19 @@
|
|||
import sockets, asyncio, strutils
|
||||
|
||||
proc auth(client: PAsyncSocket) {.async.} =
|
||||
await send(client, "Auth\c\L")
|
||||
|
||||
proc processRequest(client: PAsyncSocket, test: string, closeSock: bool = true) {.async.} =
|
||||
assert test == "ahha"
|
||||
assert client != nil
|
||||
echo("Test = ", test)
|
||||
let line = await(readLine(client))
|
||||
echo("Read: ", line)
|
||||
|
||||
for i in 0 .. 10:
|
||||
await auth(client)
|
||||
#await send(client, "Auth\c\L")
|
||||
|
||||
await send(client, "Goodbye.\c\L")
|
||||
#await send(client, "Goodbye.\c\L")
|
||||
#await send(client, "Goodbye.\c\L")
|
||||
if closeSock:
|
||||
client.close()
|
||||
|
||||
|
|
@ -24,8 +28,8 @@ proc processServer() {.async.} =
|
|||
while true:
|
||||
let client: PAsyncSocket = await(accept(sock))
|
||||
assert client != nil
|
||||
await processRequest(client, "ahha", false)
|
||||
await processRequest(client, "ahha")
|
||||
|
||||
reg processRequest(client, "ahha")
|
||||
|
||||
var disp = newDispatcher(false)
|
||||
disp.register(processServer, nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue