Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save guyguyon/c0d6f5b073ea3bf38c92d0d646895c35 to your computer and use it in GitHub Desktop.
// node-request-context/index.js
const Namespace = require('./namespace');
const namespaces = {};
function createNamespace(name) {
if (namespaces[name]) { throw new Error(`A namespace for ${name} is already exists`); }
const namespace = new Namespace();
namespaces[name] = namespace;
createHooks(namespace); // wait for explanation below
return namespace;
}
function getNamespace(name) {
return namespaces[name];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment