From 2239ecb74941cd5ba2dd4ac0866c20adc3ca5207 Mon Sep 17 00:00:00 2001 From: Andrey Pechkurov Date: Thu, 26 Mar 2020 15:11:06 +0300 Subject: [PATCH] benchmark: fix error on server close in AsyncLocalStorage benchmark --- benchmark/async_hooks/async-resource-vs-destroy.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/benchmark/async_hooks/async-resource-vs-destroy.js b/benchmark/async_hooks/async-resource-vs-destroy.js index 1894e4e8777b8b..d48510d8929ab2 100644 --- a/benchmark/async_hooks/async-resource-vs-destroy.js +++ b/benchmark/async_hooks/async-resource-vs-destroy.js @@ -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; }