-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
AsyncEverything related to Nim's asyncEverything related to Nim's asyncError MessagesStandard Library
Description
I've checked open issues related to "callback", and could not find anthing similar, so I think it's a new issue. It's also been posted in the forum, in case someone knows a work-around.
It seems to be related mixing forward declarations with async code. Here is an example that causes the issue. It has to be defined as two different modules, otherwise I could not produce the error.
# modulea
import asyncdispatch
import asyncnet
type
QueueID* = uint32
Msg*[T: not (ref|string|seq)] = object
content*: T
proc myQueue*(): QueueID =
QueueID(0)
proc sendMsgInternally[T](q: QueueID, m: ptr[Msg[T]]): void =
echo("Sending message internally to " & $q)
proc sendMsgExternally[T](q: QueueID, m: ptr[Msg[T]], size: uint32) {.async.}
proc sendMsg*[T](q: QueueID, m: ptr[Msg[T]]): void =
# fill m with data ...
if q == myQueue():
sendMsgInternally(q, m)
else:
let size = uint32(sizeof(Msg[T]))
asyncCheck sendMsgExternally(q, m, size)
proc sendMsgExternally[T](q: QueueID, m: ptr[Msg[T]], size: uint32) {.async.} =
echo("Sending message across the cluster to " & $q)
var sock = newAsyncSocket()
await sock.send(pointer(m), int(size))# moduleb
import modulea
type
TstMsg = Msg[int]
proc testIt() =
var m: TstMsg
m.content = 42
var dst = QueueID(99)
sendMsg(dst, addr m)
testIt()Metadata
Metadata
Assignees
Labels
AsyncEverything related to Nim's asyncEverything related to Nim's asyncError MessagesStandard Library