Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scristobal/clean-this-mess
A simple utility to subscribe and run tasks before closing a nodejs program
https://github.com/scristobal/clean-this-mess
Last synced: about 5 hours ago
JSON representation
A simple utility to subscribe and run tasks before closing a nodejs program
- Host: GitHub
- URL: https://github.com/scristobal/clean-this-mess
- Owner: scristobal
- License: gpl-3.0
- Created: 2021-10-05T19:28:29.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T04:14:58.000Z (7 months ago)
- Last Synced: 2024-09-27T20:38:14.759Z (about 1 month ago)
- Language: TypeScript
- Size: 1.35 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clean-this-mess
A simple utility to subscribe and run tasks before a nodejs program exits (or throws an uncaught exception) ๐งน
## Install
From NPM
```bash
npm i 'clean-this-mess'
```## Usage
### Adding tasks to the exit queue
Import the `cleanup` function as a default ESM export, pass any function(s) (even asynchronous) that you want to run before the program exits.
```typescript
import cleanup from 'clean-this-mess';cleanup(() => 'Goodbye ๐');
```> Note: order of execution is not warrantied, if your functions are async they do not wait for each other, they are added to the micro task queue at once, eg. `Promise.all`
### Remove tasks from the exit queue
If you change your mind and want to remove a task, the `cleanup` function returns a undo method that can be called to remove the task.
```typescript
import cleanup from 'clean-this-mess';const removeSayGoodbye = cleanup(() => 'Goodbye ๐');
removeSayGoodbye();
```