# terminatable_sleep

> Terminatable spleep

Latest version **0.0.1** (published 2023-07-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install terminatable_sleep
pnpm add terminatable_sleep
yarn add terminatable_sleep
bun add terminatable_sleep
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2023-07-28 |
| First published | 2023-07-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nicklasos |
| Maintainers | nicklasos |
| Keywords | sleep |

## Links

- npm: https://www.npmjs.com/package/terminatable_sleep
- Repository: https://github.com/nicklasos/terminatable_sleep
- Homepage: https://github.com/nicklasos/terminatable_sleep#readme
- Issues: https://github.com/nicklasos/terminatable_sleep/issues
- npm.io page: https://npm.io/package/terminatable_sleep

## Recent versions

- 0.0.1 (latest) — 2023-07-28

## README

# Terminatable sleep
Terminatable sleep for nodejs apps

Install:
```
npm i terminatable_sleep
```

How to use:
```js
const {terminator, terminatableSleep} = require("terminatable_sleep");

// example
function closeConnection() {
    return new Promise(resolve => {
        setTimeout(() => {
            console.log('Close connection');
            resolve();
        }, 500);
    });
}

terminator.init({
    beforeExit: async () => {
        console.log('Before exit');

        await closeConnection();

        console.log('Connection closed');
    }
});

(async () => {

    while (true) {

        console.log('Working...');

        await terminatableSleep(15000, cancel => {
            // Call the cancel() function to cancel the sleep

            terminator.onTerminate(cancel);
        });

        // or just use await terminatableSleep(15000, terminator.onTerminate);
        
        if (terminator.isTerminating()) {
            break;
        }
    }

})();
```
Run your program and then hit CTRL+C

---
_Source: https://npm.io/package/terminatable_sleep · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
