Skip to content

Instantly share code, notes, and snippets.

@guyguyon
Created November 23, 2017 16:43
Show Gist options
  • Select an option

  • Save guyguyon/a2d74eabf79c883688bfb8f73c5074fe to your computer and use it in GitHub Desktop.

Select an option

Save guyguyon/a2d74eabf79c883688bfb8f73c5074fe to your computer and use it in GitHub Desktop.
// node-request-context/namespace.js
const asyncHooks = require('async_hooks');
class Namespace {
constructor() {
this.context = {};
}
run(fn) {
const eid = asyncHooks.executionAsyncId();
this.context[eid] = {};
fn();
}
}
module.exports = Namespace;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment