diff --git a/src/Queue.ts b/src/Queue.ts index 5d3ea41..437a2ca 100644 --- a/src/Queue.ts +++ b/src/Queue.ts @@ -1,4 +1,4 @@ -import { NativeModules } from 'react-native'; +import { NativeModules, AppState } from 'react-native'; import { FALSE, Job, RawJob } from './models/Job'; import { JobStore } from './models/JobStore'; @@ -223,7 +223,11 @@ export class Queue { await Promise.all(resetTasks); } private scheduleQueue() { - this.timeoutId = setTimeout(this.runQueue, this.updateInterval); + if (AppState.currentState === 'active') { + this.timeoutId = setTimeout(this.runQueue, this.updateInterval); + } else { + this.runQueue(); + } } private runQueue = async () => { if (!this.isActive) { diff --git a/src/Worker.ts b/src/Worker.ts index 241daa9..b0a9e9e 100644 --- a/src/Worker.ts +++ b/src/Worker.ts @@ -1,3 +1,4 @@ +import { AppState } from 'react-native'; import { Job, RawJob } from './models/Job'; export const CANCEL = 'rn_job_queue_cancel'; @@ -78,7 +79,7 @@ export class Worker

{ const job = { ...rawJob, ...{ payload } }; this.executionCount++; this.onStart(job); - if (timeout > 0) { + if (timeout > 0 && AppState.currentState === 'active') { return this.executeWithTimeout(job, timeout); } else { return this.executer(payload, job.id);