From 7a5c4e95471ba5b892b3633b84846c62e82dbffa Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 17 Aug 2021 16:57:39 -0400 Subject: [PATCH] Throw when useLists() called concurrently Related feedback: - https://github.com/gorhill/uBlock/pull/3836/files#r690687656 --- platform/nodejs/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/nodejs/index.js b/platform/nodejs/index.js index 08a65396d..e8c0171bb 100644 --- a/platform/nodejs/index.js +++ b/platform/nodejs/index.js @@ -146,6 +146,10 @@ function compileList({ name, raw }, compiler, writer, options = {}) { /******************************************************************************/ async function useLists(lists, options = {}) { + if ( useLists.promise !== null ) { + throw new Error('Pending useLists() operation'); + } + // Remove all filters snfe.reset(); @@ -174,13 +178,17 @@ async function useLists(lists, options = {}) { promises.push(promise.then(list => consumeList(list))); } - await Promise.all(promises); + useLists.promise = Promise.all(promises); + await useLists.promise; + useLists.promise = null; // Commit changes snfe.freeze(); snfe.optimize(); } +useLists.promise = null; + /******************************************************************************/ class MockStorage {