summary refs log tree commit diff stats
path: root/tests/async
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2018-09-22 15:59:47 +0200
committerLemonBoy <thatlemon@gmail.com>2018-09-22 17:30:17 +0200
commit75a981cf80cb9f4cdff83a6ff525f6428b3ab5f1 (patch)
treedf4871d616f9ed161d1893b5ddfcb78d9622b135 /tests/async
parent6b5e2adfd08796eb73dbec479f3e40b22a366c98 (diff)
downloadNim-75a981cf80cb9f4cdff83a6ff525f6428b3ab5f1.tar.gz
Skip nested procedures in .async. macro
Fixes #3075
Diffstat (limited to 'tests/async')
-rw-r--r--tests/async/t3075.nim29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/async/t3075.nim b/tests/async/t3075.nim
new file mode 100644
index 000000000..d26aa0a36
--- /dev/null
+++ b/tests/async/t3075.nim
@@ -0,0 +1,29 @@
+import asyncnet, asyncdispatch, strtabs
+
+type
+  WebSocketCallback = proc (client: WebSocket, message: WebSocketMessage) {.closure, gcsafe.}
+  WebSocketRecvClosure = proc (ws: WebSocket): Future[string] {.gcsafe.}
+
+  WebSocketMessage = ref object
+    msg: string
+
+  WebSocket = ref object
+    socket:     AsyncSocket
+    header:     StringTableRef
+    onOpen:     WebSocketCallback
+    onMessage:  WebSocketCallback
+    onClose:    WebSocketCallback
+
+proc recv(ws: WebSocket, p: WebSocketRecvClosure): Future[string] {.async.}=
+  if not ws.socket.isClosed():
+    result = await ws.p()
+    if result == "":
+      ws.socket.close()
+      if ws.onClose != nil:
+        ws.onClose(ws, nil)
+  return result
+
+proc reŅvSize(ws: WebSocket, size: int): Future[string] {.async.} =
+  proc recvSizeClosure(ws: WebSocket): Future[string] {.async.} =
+    return await ws.socket.recv(size)
+  return await ws.recv(recvSizeClosure)