Skip to content

Commit aac8ddc

Browse files
committed
docs: cleanup code snippets
1 parent 1dabf81 commit aac8ddc

File tree

1 file changed

+4
-61
lines changed

1 file changed

+4
-61
lines changed

README.md

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
# React Native Queue
44
#### Simple. Powerful. Persistent.
55

6-
[![Build Status](https://travis-ci.org/billmalarky/react-native-queue.svg?branch=master)](https://travis-ci.org/billmalarky/react-native-queue)
7-
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/billmalarky/react-native-queue/blob/master/LICENSE)
8-
[![ESLint](https://img.shields.io/badge/eslint-ok-green.svg)](https://github.com/billmalarky/react-native-queue/blob/master/.eslintrc.js)
9-
[![JSDoc](https://img.shields.io/badge/jsdoc-100%25%20code%20documentation-green.svg)](http://usejsdoc.org/)
10-
[![Coverage Status](https://coveralls.io/repos/github/billmalarky/react-native-queue/badge.svg?branch=master)](https://coveralls.io/github/billmalarky/react-native-queue?branch=master)
6+
[![Node.js CI](https://github.com/sourcetoad/react-native-queue/master/workflows/build.yml/badge.svg)](https://github.com/sourcetoad/react-native-queue/master/workflows/build.yml)
7+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sourcetoad/react-native-queue/blob/master/LICENSE)
118

129
A React Native at-least-once priority job queue / task queue backed by persistent Realm storage. Jobs will persist until completed, even if user closes and re-opens app. React Native Queue is easily integrated into OS background processes (services) so you can ensure the queue will continue to process until all jobs are completed even if app isn't in focus. It also plays well with Workers so your jobs can be thrown on the queue, then processed in dedicated worker threads for greatly improved processing performance.
1310

@@ -23,7 +20,6 @@ A React Native at-least-once priority job queue / task queue backed by persisten
2320
* [Advanced Usage Examples](#advanced-usage-examples)
2421
* [Advanced Job Full Example](#advanced-job-full-example)
2522
* [OS Background Task Full Example](#os-background-task-full-example)
26-
* [Tutorials](#tutorials)
2723

2824
## Features
2925

@@ -86,7 +82,6 @@ Creating and processing jobs consists of:
8682
4. Starting the queue (note this happens automatically on job creation, but sometimes the queue must be explicitly started such as in a OS background task or on app restart). Queue can be started with a lifespan in order to limit queue processing time.
8783

8884
```js
89-
9085
import queueFactory from 'react-native-queue';
9186

9287
// Of course this line needs to be in the context of an async function,
@@ -104,7 +99,6 @@ queue.addWorker('example-job', async (id, payload) => {
10499
resolve();
105100
}, 5000);
106101
});
107-
108102
});
109103

110104
// Create a couple "example-job" jobs.
@@ -144,7 +138,6 @@ queue.createJob('example-job', {
144138
});
145139

146140
console.log('The above jobs are processing in the background of app now.');
147-
148141
```
149142

150143
## Options and Job Lifecycle Callbacks
@@ -156,7 +149,6 @@ queue.addWorker() accepts an options object in order to tweak standard functiona
156149
**IMPORTANT: Job Lifecycle callbacks are called asynchronously.** They do not block job processing or each other. Don't put logic in onStart that you expect to be completed before the actual job process begins executing. Don't put logic in onFailure you expect to be completed before onFailed is called. You can, of course, assume that the job process has completed (or failed) before onSuccess, onFailure, onFailed, or onComplete are asynchonrously called.
157150

158151
```js
159-
160152
queue.addWorker('job-name-here', async (id, payload) => { console.log(id); }, {
161153

162154
// Set max number of jobs for this worker to process concurrently.
@@ -172,39 +164,28 @@ queue.addWorker('job-name-here', async (id, payload) => { console.log(id); }, {
172164
// As such, do not place any logic in onStart that your actual job worker function will depend on,
173165
// this type of logic should of course go inside the job worker function itself.
174166
onStart: async (id, payload) => {
175-
176-
console.log('Job "job-name-here" with id ' + id + ' has started processing.');
177-
167+
console.log('Job "job-name-here" with id ' + id + ' has started processing.');
178168
},
179169

180170
// onSuccess job callback handler is fired after a job successfully completes processing.
181171
onSuccess: async (id, payload) => {
182-
183172
console.log('Job "job-name-here" with id ' + id + ' was successful.');
184-
185173
},
186174

187175
// onFailure job callback handler is fired after each time a job fails (onFailed also fires if job has reached max number of attempts).
188176
onFailure: async (id, payload) => {
189-
190177
console.log('Job "job-name-here" with id ' + id + ' had an attempt end in failure.');
191-
192178
},
193179

194180
// onFailed job callback handler is fired if job fails enough times to reach max number of attempts.
195181
onFailed: async (id, payload) => {
196-
197182
console.log('Job "job-name-here" with id ' + id + ' has failed.');
198-
199183
},
200184

201185
// onComplete job callback handler fires after job has completed processing successfully or failed entirely.
202186
onComplete: async (id, payload) => {
203-
204187
console.log('Job "job-name-here" with id ' + id + ' has completed processing.');
205-
206188
}
207-
208189
});
209190

210191
```
@@ -214,9 +195,7 @@ queue.addWorker('job-name-here', async (id, payload) => { console.log(id); }, {
214195
queue.createJob() accepts an options object in order to tweak standard functionality.
215196

216197
```js
217-
218198
queue.createJob('job-name-here', {foo: 'bar'}, {
219-
220199
// Higher priority jobs (10) get processed before lower priority jobs (-10).
221200
// Any int will work, priority 1000 will be processed before priority 10, though this is probably overkill.
222201
// Defaults to 0.
@@ -239,10 +218,7 @@ queue.createJob('job-name-here', {foo: 'bar'}, {
239218
// Number of times to attempt a failing job before marking job as failed and moving on.
240219
// Defaults to 1.
241220
attempts: 4, // If this job fails to process 4 times in a row, it will be marked as failed.
242-
243-
});
244-
245-
221+
});
246222
```
247223

248224
## Testing with Jest
@@ -262,7 +238,6 @@ Because realm will write database files to the root test directory when running
262238
#### Advanced Job Full Example
263239

264240
```js
265-
266241
import React, { Component } from 'react';
267242
import {
268243
Platform,
@@ -284,11 +259,9 @@ export default class App extends Component<{}> {
284259
};
285260

286261
this.init();
287-
288262
}
289263

290264
async init() {
291-
292265
const queue = await queueFactory();
293266

294267
//
@@ -322,7 +295,6 @@ export default class App extends Component<{}> {
322295
resolve();
323296
}, 1000);
324297
});
325-
326298
});
327299

328300
//
@@ -350,7 +322,6 @@ export default class App extends Component<{}> {
350322
resolve();
351323
}, 1000);
352324
});
353-
354325
});
355326

356327
queue.addWorker('job-chain-2nd-step', async (id, payload) => {
@@ -370,7 +341,6 @@ export default class App extends Component<{}> {
370341
resolve();
371342
}, 1000);
372343
});
373-
374344
});
375345

376346
queue.addWorker('job-chain-final-step', async (id, payload) => {
@@ -385,7 +355,6 @@ export default class App extends Component<{}> {
385355
resolve();
386356
}, 1000);
387357
});
388-
389358
});
390359

391360
// Start queue to process any jobs that hadn't finished when app was last closed.
@@ -395,15 +364,13 @@ export default class App extends Component<{}> {
395364
this.setState({
396365
queue
397366
});
398-
399367
}
400368

401369
makeJob(jobName, payload = {}) {
402370
this.state.queue.createJob(jobName, payload);
403371
}
404372

405373
render() {
406-
407374
return (
408375
<View style={styles.container}>
409376
<Text style={styles.welcome}>
@@ -431,8 +398,6 @@ const styles = StyleSheet.create({
431398
margin: 10,
432399
},
433400
});
434-
435-
436401
```
437402

438403
#### OS Background Task Full Example
@@ -442,7 +407,6 @@ For the purpose of this example we will use the [React Native Background Task](h
442407
Follow the [installation steps](https://github.com/jamesisaac/react-native-background-task#installation) for React Native Background Task.
443408

444409
```js
445-
446410
import React, { Component } from 'react';
447411
import {
448412
Platform,
@@ -470,7 +434,6 @@ BackgroundTask.define(async () => {
470434
} else {
471435
await AsyncStorage.setItem('c3poData', 'C-3PO arbitrary data loaded!');
472436
}
473-
474437
});
475438

476439
// Start the queue with a lifespan
@@ -482,11 +445,9 @@ BackgroundTask.define(async () => {
482445

483446
// finish() must be called before OS hits timeout.
484447
BackgroundTask.finish();
485-
486448
});
487449

488450
export default class App extends Component<{}> {
489-
490451
constructor(props) {
491452
super(props);
492453

@@ -496,11 +457,9 @@ export default class App extends Component<{}> {
496457
};
497458

498459
this.init();
499-
500460
}
501461

502462
async init() {
503-
504463
const queue = await queueFactory();
505464

506465
// Add the worker.
@@ -515,7 +474,6 @@ export default class App extends Component<{}> {
515474
this.setState({
516475
queue
517476
});
518-
519477
}
520478

521479
componentDidMount() {
@@ -532,7 +490,6 @@ export default class App extends Component<{}> {
532490
}
533491

534492
async checkData() {
535-
536493
const lukeData = await AsyncStorage.getItem('lukeData');
537494
const c3poData = await AsyncStorage.getItem('c3poData');
538495

@@ -542,11 +499,9 @@ export default class App extends Component<{}> {
542499
c3poData: (c3poData) ? c3poData : 'No data loaded from OS background task yet for C-3PO.'
543500
}
544501
});
545-
546502
}
547503

548504
render() {
549-
550505
let output = 'No data loaded from OS background task yet.';
551506
if (this.state.data) {
552507
output = JSON.stringify(this.state.data);
@@ -566,7 +521,6 @@ export default class App extends Component<{}> {
566521
<Text>{output}</Text>
567522
</View>
568523
);
569-
570524
}
571525
}
572526

@@ -583,15 +537,4 @@ const styles = StyleSheet.create({
583537
margin: 10,
584538
},
585539
});
586-
587540
```
588-
589-
## Tutorials
590-
591-
#### Easy OS Background Tasks in React Native
592-
593-
An in-depth guide to setting up background tasks / services that run periodically when the app is closed.
594-
595-
* [Hosted on Medium](https://hackernoon.com/easy-os-background-tasks-in-react-native-bc4476c48b8a)
596-
* [Raw Markdown](/docs/easy-os-background-tasks-in-react-native.md)
597-

0 commit comments

Comments
 (0)