Jeff-Lewis / cls-hooked

cls-hooked : CLS using AsynWrap or async_hooks instead of async-listener for node 4.7+
BSD 2-Clause "Simplified" License
759 stars 89 forks source link

The right way to force run with empty context? #27

Open Strate opened 6 years ago

Strate commented 6 years ago

Hi,

I'm implementing a queue system, using https://caolan.github.io/async/docs.html#queue

And I need to enforce each worker run with empty new context. I found this way:

cosnt ns = clsHooked.createNamespace("test");
function runInNewContext(fn) {
  return ns.bind(fn, {})()
}

Is this a best way to do this, or there is a better way?