Re:MongoDB singleton connection in Node.Js
by chimeracoder on Friday April 05, 2013 @11:47AM
(#5499112)
Be careful of double-checked locking errors: http://en.wikipedia.org/wiki/Double-checked_locking
[ Parent
| on HN ]
Re:MongoDB singleton connection in Node.Js
by lukesandberg on Friday April 05, 2013 @12:00PM
(#5499202)
seeing as this is node you won't need a lock (and since it is single threaded there are no cross thread visibility issues).
What you do need is a state variable that indicates if the connection is uninitialized, loading, or ready. And if it is in the loading state you need to have a list of callbacks so that concurrent requests can be added to the list.