https://github.com/netsells/catch-continue
https://github.com/netsells/catch-continue
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/netsells/catch-continue
- Owner: netsells
- Created: 2020-02-27T14:55:43.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-27T08:53:45.000Z (about 4 years ago)
- Last Synced: 2025-02-02T18:52:12.095Z (3 months ago)
- Language: JavaScript
- Size: 99.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CatchContinue
A class to allow you to run segments of code in order, catch errors, and retry
or continue from where an error occured.## Installation
```bash
yarn add @netsells/catch-continue
```## Usage
```javascript
import CatchContinue from '@netsells/catch-continue';async function myFunction() {
const cc = new CatchContinue();cc.add(() => {
// any thrown error will pause execution
});cc.add(() => {
return Promise((resolve, reject) => {
// rejecting the promise will pause execution
});
});cc.add(async () => {
await someCode(); // errors thrown or promises rejected will pause execution
});try {
await cc.run('any', 'arguments'); // Any passed arguments will be passed to the segment functions
} catch(e) {
cc.continue(); // will run from the segment after the one which errored// OR
cc.retry(); // will run starting from the failed segment
}
}
```