So I been using async stuff and a global connections seq for a while in production and stuff. I don't have any issues with this, but it appears to cause a warning.
What can I do about it? Should I silence the warning? What kind of issues should I expect? Under my impressions is that async stuff should all be using the same thread so sharing things like seq should be fine?
Is there a better way to write this code?
nim-1.0.0/lib/pure/asyncmacro.nim(271, 31) Warning: 'cbIter' is not GC-safe as it accesses 'connections' which is a global using GC'ed memory [GcUnsafe2]
https://github.com/treeform/ws/blob/master/tests/chat.nim#L3
This prompted the question: https://github.com/treeform/ws/issues/9
Try to compile with --threads:on to turn this warning into an error. Your code is not threadsafe. The following variant should work:
var connections {.threadvar.}: seq[WebSocket] # no explicit init here, but the default of @[] works fine