diff options
author | deansher <deansherthompson@gmail.com> | 2019-01-28 08:12:24 -0500 |
---|---|---|
committer | deansher <deansherthompson@gmail.com> | 2019-01-28 08:12:24 -0500 |
commit | d60f8ab99181ea18cc534728ba4d0470c0ca1bce (patch) | |
tree | 64cef5bc336a6d0038dcb47a4e3b1cd30ed434d7 /tests/async/tasyncawait.nim | |
parent | a6de0274ee768d135bab280d2b2700a0bb475300 (diff) | |
parent | 9402c82e803d133e0b845a7c5c79c261781e7d8d (diff) | |
download | Nim-d60f8ab99181ea18cc534728ba4d0470c0ca1bce.tar.gz |
Merge remote-tracking branch 'upstream/devel' into devel
Diffstat (limited to 'tests/async/tasyncawait.nim')
-rw-r--r-- | tests/async/tasyncawait.nim | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/async/tasyncawait.nim b/tests/async/tasyncawait.nim index fcb48a1f5..1e6cf3761 100644 --- a/tests/async/tasyncawait.nim +++ b/tests/async/tasyncawait.nim @@ -1,7 +1,7 @@ discard """ output: "5000" """ -import asyncdispatch, nativesockets, net, strutils, os +import asyncdispatch, asyncnet, nativesockets, net, strutils, os var msgCount = 0 @@ -12,20 +12,22 @@ const var clientCount = 0 proc sendMessages(client: AsyncFD) {.async.} = - for i in 0 .. <messagesToSend: + for i in 0 ..< messagesToSend: await send(client, "Message " & $i & "\c\L") proc launchSwarm(port: Port) {.async.} = - for i in 0 .. <swarmSize: - var sock = newAsyncNativeSocket() + for i in 0 ..< swarmSize: + var sock = createAsyncNativeSocket() await connect(sock, "localhost", port) await sendMessages(sock) closeSocket(sock) proc readMessages(client: AsyncFD) {.async.} = + # wrapping the AsyncFd into a AsyncSocket object + var sockObj = newAsyncSocket(client) while true: - var line = await recvLine(client) + var line = await recvLine(sockObj) if line == "": closeSocket(client) clientCount.inc @@ -37,7 +39,7 @@ proc readMessages(client: AsyncFD) {.async.} = doAssert false proc createServer(port: Port) {.async.} = - var server = newAsyncNativeSocket() + var server = createAsyncNativeSocket() block: var name: Sockaddr_in name.sin_family = toInt(AF_INET).uint16 |