Created
June 23, 2017 13:22
-
-
Save lukashavrlant/6a4775efbb09e24c2eaca58a1fdd724f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const continuation = require('continuation-local-storage'); | |
const uuid = require('node-uuid'); | |
const NAMESPACE = 'luha-test'; | |
const namespace = continuation.createNamespace(NAMESPACE); | |
for (let i = 0; i < 5; i++) { | |
namespace.run(function () { | |
const id = uuid.v4(); | |
namespace.set('correlationId', id); | |
setTimeout(() => printCorrelationId(id), Math.random() * 3000); | |
}); | |
} | |
function printCorrelationId(generatedId) { | |
const ns = continuation.getNamespace(NAMESPACE); | |
const correlationId = ns.get('correlationId'); | |
console.log(`Passed correlation Id is ${generatedId}, continuation correlation Id is ${correlationId}. Are they equal? ${generatedId === correlationId}`); | |
new Promise(function (resolve) { | |
setTimeout(resolve, Math.random() * 3000); | |
}).then(function () { | |
printCorrelationId(generatedId); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment