Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLSContext now supports continuations with async-await #201

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/zipkin-context-cls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"license": "Apache-2.0",
"repository": "https://github.com/openzipkin/zipkin-js",
"dependencies": {
"continuation-local-storage": "^3.1.7"
"cls-hooked": "^4.2.2"
},
"devDependencies": {
"babel-cli": "^6.23.0",
"babel-eslint": "^8.2.2",
"mocha": "^3.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/zipkin-context-cls/src/CLSContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {createNamespace, getNamespace} = require('continuation-local-storage');
const {createNamespace, getNamespace} = require('cls-hooked');

module.exports = class CLSContext {
constructor(namespace = 'zipkin') {
Expand Down
3 changes: 2 additions & 1 deletion packages/zipkin-context-cls/test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
},
"globals": {
"expect": true
}
},
"parser": "babel-eslint"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, eslint was freaking out.

}
20 changes: 20 additions & 0 deletions packages/zipkin-context-cls/test/CLSContext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,24 @@ describe('CLSContext', () => {
setTimeout(callback, 10);
});
});
it('should support async-await', async () => {
const ctx = new CLSContext();

async function log() {
return ctx.getContext();
}

async function afn() {
const cid1 = await log(1);
const cid2 = await log(2);
return {cid1, cid2};
}

async function newP(id) {
const {cid1, cid2} = await ctx.letContext(id, () => afn());
expect(cid1).to.not.equal(null);
expect(cid2).to.not.equal(null);
}
await newP(1); // eslint-disable-line
});
});