async-local-storage
Advanced tools
Comparing version 2.2.0 to 2.3.0
24
als.js
@@ -19,2 +19,3 @@ const asyncHooks = require('async_hooks'); | ||
let defaultLinkedTop = false; | ||
let enabledCreatedAt = true; | ||
@@ -59,6 +60,7 @@ function isUndefined(value) { | ||
init: function init(id, type, triggerId) { | ||
const data = {}; | ||
// init, set the created time | ||
const data = { | ||
created: nano.now(), | ||
}; | ||
if (enabledCreatedAt) { | ||
data.created = nano.now(); | ||
} | ||
const parentId = triggerId || currentId; | ||
@@ -214,3 +216,3 @@ // not trigger by itself, add parent | ||
/* istanbul ignore if */ | ||
if (!data) { | ||
if (!data || !enabledCreatedAt) { | ||
return -1; | ||
@@ -243,1 +245,15 @@ } | ||
}; | ||
/** | ||
* Enable the create time of data | ||
*/ | ||
exports.enableCreateTime = function enableCreateTime() { | ||
enabledCreatedAt = true; | ||
}; | ||
/** | ||
* Disable the create time of data | ||
*/ | ||
exports.disableCreateTime = function disableCreateTime() { | ||
enabledCreatedAt = false; | ||
}; |
@@ -264,6 +264,12 @@ const path = require('path'); | ||
als.scope(); | ||
const id = als.currentId(); | ||
let id = als.currentId(); | ||
return delay(10).then(() => { | ||
const use = als.use(id); | ||
expect(use).toBeGreaterThanOrEqual(9 * 1000 * 1000); | ||
id = als.currentId(); | ||
als.disableCreateTime(); | ||
return delay(10); | ||
}).then(() => { | ||
const use = als.use(id); | ||
expect(use).toBe(-1); | ||
}); | ||
@@ -270,0 +276,0 @@ }); |
@@ -0,1 +1,9 @@ | ||
# 2.3.0 | ||
* support enable/disable create time for save memory | ||
# 2.2.0 | ||
* add getAllData function | ||
# 2.1.0 | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "async-local-storage", | ||
"description": "Get the value like thread-local storage in threaded programming", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"author": "Tree Xie <vicansocanbico@gmail.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -195,1 +195,16 @@ # async-local-storage | ||
### enableCreateTime | ||
enable create time of data, default is enabled. | ||
```js | ||
als.enableCreateTime(); | ||
``` | ||
### disableCreateTime | ||
disable create time of data, it can save memory. | ||
```js | ||
als.disableCreateTime(); | ||
``` |
164786
758
209