Closed enthus1ast closed 6 years ago
Yep, we need to get rid of the global.
Nim needs a way for libraries to initialise thread-local vars.
CC @Araq
We had introduced a mechanism for that but it encouraged races everywhere so we removed it again.
Well, re: the patch: We can make it a thread-local and init it on first usage, but then it'll break for server designs where the same connection can hop between threads. It would definitely have to be documented.
Moving it into the function scope seems wrong to me, as pings will never be answered (the table will always be empty for every new request unpack).
@Araq how did it encourage races? Maybe the mechanism's implementation was wrong? :P
@niv mabye something like a websocketContext
?
Why not use a SharedTable instead? Needs protect
and dispose
for the Future but it's possible.
Wouldn't this break? The global map is global because it is needed between readData calls.
What about making it thread-local instead (though that will potentially break too for multithreaded httpds that shard out request handlers)?
Maybe this needs a bigger API change and move responsibility for this elsewhere.