Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Queue.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/Worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AppState } from 'react-native';
import { Job, RawJob } from './models/Job';

export const CANCEL = 'rn_job_queue_cancel';
Expand Down Expand Up @@ -78,7 +79,7 @@ export class Worker<P extends object> {
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);
Expand Down