Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. const cls = require(`cls-hooked`);
  2. const uuid = require(`uuid`);
  3.  
  4. const store = cls.createNamespace(`correlation-id-namespace`);
  5.  
  6. const CORRELATION_ID_KEY = `correlation-id`;
  7.  
  8. function withId(fn, id) {
  9. store.run(() => {
  10. store.set(CORRELATION_ID_KEY, id || uuid.v4());
  11. fn();
  12. });
  13. }
  14.  
  15. function getId() {
  16. return store.get(CORRELATION_ID_KEY);
  17. }
  18.  
  19. module.exports = {
  20. withId,
  21. getId,
  22. bindEmitter: store.bindEmitter.bind(store),
  23. bind: store.bind.bind(store),
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement