Is it possible to have “thread” local variables in Node?

前端 未结 3 1054
萌比男神i
萌比男神i 2021-02-05 08:16

I would like to store a variable that is shared between all stack frames (top down) in a call chain. Much like ThreadLocal in Java or C#.

I have found https://github.com

3条回答
  •  执念已碎
    2021-02-05 08:48

    Yes, it is possible. Thomas Watson has spoken about it at NodeConf Oslo 2016 in his Instrumenting Node.js in Production (alt.link).

    It uses Node.js tracing - AsyncWrap (which should eventually become a well-established part of the public Node API). You can see an example in the open-source Opbeat Node agent or, perhaps even better, check out the talk slides and example code.

提交回复
热议问题