From e15951dce531028f5590aa50af75d80a75d12a82 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 14 Apr 2023 10:26:45 -0400 Subject: [PATCH] Convert remaining vAPI.setTimeout to vAPI.defer Related commit: - https://github.com/gorhill/uBlock/commit/91f9795023de45dcee17567d3faef8c65335e2e0 --- src/1p-filters.html | 9 +++++---- src/asset-viewer.html | 7 ++++--- src/code-viewer.html | 10 ++++++---- src/devtools.html | 7 ++++--- src/js/codemirror/search-thread.js | 16 ++++++---------- src/whitelist.html | 7 ++++--- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/1p-filters.html b/src/1p-filters.html index fa153ba56..3fb1c8e29 100644 --- a/src/1p-filters.html +++ b/src/1p-filters.html @@ -50,14 +50,15 @@ - - - - + + + + + diff --git a/src/asset-viewer.html b/src/asset-viewer.html index 9bda40011..b30320f9e 100644 --- a/src/asset-viewer.html +++ b/src/asset-viewer.html @@ -33,13 +33,14 @@ + + + + - - - diff --git a/src/code-viewer.html b/src/code-viewer.html index 3f4896df4..4b699feda 100644 --- a/src/code-viewer.html +++ b/src/code-viewer.html @@ -36,13 +36,15 @@ - - - - + + + + + + diff --git a/src/devtools.html b/src/devtools.html index 5598968e3..5683dc79e 100644 --- a/src/devtools.html +++ b/src/devtools.html @@ -41,13 +41,14 @@ + + + + - - - diff --git a/src/js/codemirror/search-thread.js b/src/js/codemirror/search-thread.js index 7b33fb126..72cf9151d 100644 --- a/src/js/codemirror/search-thread.js +++ b/src/js/codemirror/search-thread.js @@ -103,11 +103,13 @@ if ( // Main context { - const workerTTL = 5 * 60 * 1000; + const workerTTL = { min: 5 }; const pendingResponses = new Map(); + const workerTTLTimer = vAPI.defer.create(( ) => { + shutdown(); + }); let worker; - let workerTTLTimer; let messageId = 1; const onWorkerMessage = function(e) { @@ -131,11 +133,8 @@ if ( }; const shutdown = function() { - if ( workerTTLTimer !== undefined ) { - clearTimeout(workerTTLTimer); - workerTTLTimer = undefined; - } if ( worker === undefined ) { return; } + workerTTLTimer.off(); worker.terminate(); worker.onmessage = undefined; worker = undefined; @@ -148,10 +147,7 @@ if ( worker = new Worker('js/codemirror/search-thread.js'); worker.onmessage = onWorkerMessage; } - if ( workerTTLTimer !== undefined ) { - clearTimeout(workerTTLTimer); - } - workerTTLTimer = vAPI.setTimeout(shutdown, workerTTL); + workerTTLTimer.offon(workerTTL); }; const needHaystack = function() { diff --git a/src/whitelist.html b/src/whitelist.html index 4ea444afc..02d31d8d1 100644 --- a/src/whitelist.html +++ b/src/whitelist.html @@ -45,13 +45,14 @@ + + + + - - -