benchmark: fix error on server close in AsyncLocalStorage benchmark

PR-URL: https://github.com/nodejs/node/pull/32503
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
Andrey Pechkurov authored and Michaël Zasso committed 2020-04-11 10:01:16 +02:00
1 parent 8597df48f7
commit 78b90d9bc4
1 file changed
+7 -4
@@ -35,7 +35,7 @@ function buildCurrentResource(getServe) {
function getCLS() {
const resource = executionAsyncResource();
if (resource === null || !resource[cls]) {
if (!resource[cls]) {
return null;
}
return resource[cls].state;
@@ -43,9 +43,6 @@ function buildCurrentResource(getServe) {
function setCLS(state) {
const resource = executionAsyncResource();
if (resource === null) {
return;
}
if (!resource[cls]) {
resource[cls] = { state };
} else {
@@ -116,11 +113,17 @@ function buildAsyncLocalStorage(getServe) {
function getCLS() {
const store = asyncLocalStorage.getStore();
if (store === undefined) {
return null;
}
return store.state;
}
function setCLS(state) {
const store = asyncLocalStorage.getStore();
if (store === undefined) {
return;
}
store.state = state;
}