Skip to content

Instantly share code, notes, and snippets.

@karlhorky
Created February 16, 2017 10:39
Show Gist options
  • Save karlhorky/f41c81a9a563c0b69e1d5303876b122d to your computer and use it in GitHub Desktop.
Save karlhorky/f41c81a9a563c0b69e1d5303876b122d to your computer and use it in GitHub Desktop.
request-local-storage global singleton
// Before
module.exports = {
getNamespace: getNamespace,
getCountNamespaces: getCountNamespaces,
startRequest: startRequest,
bind: bind,
patch: patch
};
// After (singleton in global namespace)
module.exports = global.continuationLocalStorage || {
getNamespace: getNamespace,
getCountNamespaces: getCountNamespaces,
startRequest: startRequest,
bind: bind,
patch: patch
};
if (!global.continuationLocalStorage) {
global.continuationLocalStorage = module.exports;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment