Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
180
rated 0 times [  187] [ 7]  / answers: 1 / hits: 28348  / 11 Years ago, mon, march 11, 2013, 12:00:00

I have a little snippet of node.js code in front of me that looks like this:



console.time(queryTime);
doAsyncIOBoundThing(function(err, results) {
console.timeEnd(queryTime);
// Process the results...
});


And of course when I run this on my (otherwise idle) development system, I get a nice console message like this:



queryTime: 564ms


However, if I put this into production, won't there likely be several async calls in progress simultaneously, and each of them will overwrite the previous timer? Or does node have some sort of magical execution context that gives each thread of execution a separate console timer namespace?


More From » node.js

 Answers
7

Just use unique labels and it will be safe. That's why you use a label, to uniquely identify the start time.



As long as you don't accidentally use a label twice everything will work exactly as intended. Also note that node has usually only one thread of execution.


[#79662] Sunday, March 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kileyr

Total Points: 112
Total Questions: 105
Total Answers: 114

Location: United States Minor Outlying Island
Member since Sat, May 28, 2022
2 Years ago
;