async-local-storage
Advanced tools
Comparing version
11
index.js
@@ -34,5 +34,2 @@ const asyncHooks = require('async_hooks'); | ||
init: function init(id, type, triggerId) { | ||
if (type === 'TickObject') { | ||
return; | ||
} | ||
// init, set the created time | ||
@@ -43,3 +40,3 @@ const data = { | ||
const parentId = triggerId || currentId; | ||
// not tigger by itself, add parent | ||
// not trigger by itself, add parent | ||
if (parentId !== id) { | ||
@@ -106,7 +103,7 @@ const parent = map.get(parentId); | ||
* @param {String} value The value | ||
* @returns {Boolean} if sucess, will return true, otherwise false | ||
* @returns {Boolean} if success, will return true, otherwise false | ||
*/ | ||
exports.set = function setValue(key, value) { | ||
/* istanbul ignore if */ | ||
if (key === 'created' || key === 'paraent') { | ||
if (key === 'created' || key === 'parent') { | ||
throw new Error('can\'t set created and parent'); | ||
@@ -148,3 +145,3 @@ } | ||
* Get the use the of id | ||
* @param {Number} id The tigger id, is optional, default is `als.currentId()` | ||
* @param {Number} id The trigger id, is optional, default is `als.currentId()` | ||
* @returns {Number} The use time(ns) of the current id | ||
@@ -151,0 +148,0 @@ */ |
{ | ||
"name": "async-local-storage", | ||
"description": "Get the value like thread-local storage in threaded programming", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"author": "Tree Xie <vicansocanbico@gmail.com>", | ||
@@ -28,2 +28,3 @@ "keywords": [ | ||
"eslint-plugin-react": "^6.8.0", | ||
"express": "^4.16.2", | ||
"ioredis": "^3.1.1", | ||
@@ -34,2 +35,3 @@ "istanbul": "^0.4.5", | ||
"mocha": "^3.1.0", | ||
"on-headers": "^1.0.1", | ||
"superagent": "^3.5.2", | ||
@@ -36,0 +38,0 @@ "supertest": "^3.0.0" |
@@ -71,2 +71,13 @@ const assert = require('assert'); | ||
// next tick | ||
app.use(async (ctx, next) => { | ||
await new Promise((resolve) => { | ||
process.nextTick(() => { | ||
assert.equal(als.get('id'), ctx.get('X-Request-Id')); | ||
resolve(); | ||
}); | ||
}); | ||
return next(); | ||
}); | ||
// session | ||
@@ -73,0 +84,0 @@ app.use(async (ctx, next) => { |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
18766
26.01%11
22.22%532
37.47%14
16.67%