From ef1a86b37e6e010ee6a5f6a226c7a2a607b18458 Mon Sep 17 00:00:00 2001 From: Cristiano Coelho Date: Sat, 24 Jul 2021 17:56:03 -0300 Subject: [PATCH] If throttle is 0, do not use interval. Fixes persistence in background. --- src/createPersistoid.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/createPersistoid.js b/src/createPersistoid.js index 349b7b819..f84fa2851 100644 --- a/src/createPersistoid.js +++ b/src/createPersistoid.js @@ -55,12 +55,18 @@ export default function createPersistoid(config: PersistConfig): Persistoid { } }) - // start the time iterator if not running (read: throttle) - if (timeIterator === null) { - timeIterator = setInterval(processNextKey, throttle) - } - lastState = state + // if no throttle, there's no point in using + // an interval, this allows background execution in RN. + if (!throttle) { + while (keysToProcess.length) { + processNextKey() + } + } else { + if (timeIterator === null) { + timeIterator = setInterval(processNextKey, throttle) + } + } } function processNextKey() {