Skip to content

Commit 777d98f

Browse files
committed
Document signal handling
Fixes #48
1 parent b4e52fc commit 777d98f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

readme.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,30 @@ await pRetry(run, {retries: 5});
228228
await pRetry(() => run('🦄'), {retries: 5});
229229
```
230230

231+
## FAQ
232+
233+
### How do I stop retries when the process receives SIGINT (Ctrl+C)?
234+
235+
Use an [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) to signal cancellation on SIGINT, and pass its `signal` to `pRetry`:
236+
237+
```js
238+
import pRetry from 'p-retry';
239+
240+
const controller = new AbortController();
241+
242+
process.once('SIGINT', () => {
243+
controller.abort(new Error('SIGINT received'));
244+
});
245+
246+
try {
247+
await pRetry(run, {signal: controller.signal});
248+
} catch (error) {
249+
console.log('Retry stopped due to:', error.message);
250+
}
251+
```
252+
253+
The package does not handle process signals itself to avoid global side effects.
254+
231255
## Related
232256

233257
- [p-timeout](https://github.com/sindresorhus/p-timeout) - Timeout a promise after a specified amount of time

0 commit comments

Comments
 (0)