# halt

> node.js addon used for safely teminating javascript execution

Latest version **2.2.0** (published 2018-02-15) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2018-02-15 |
| First published | 2015-09-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.12 |
| Dependencies | 0 |
| Unpacked size | 793.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 9 |
| Author | larwin |
| Maintainers | dianedelallee, larwin, olivierross |
| Keywords | event loop, timer, timeout, hang, halt, TerminateExecution, libuv, thread |

## Links

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

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 2.2.0 (latest) — 2018-02-15
- 2.1.0 — 2017-12-02
- 2.0.0 — 2017-11-30
- 1.2.0 — 2017-08-31
- 1.1.0 — 2017-03-23
- 1.0.20 — 2016-10-24
- 1.0.19 — 2016-04-28
- 1.0.18 — 2016-03-21
- 1.0.17 — 2015-12-09
- 1.0.16 — 2015-09-09
- 1.0.15 — 2015-09-07
- 1.0.14 — 2015-09-07
- 1.0.13 — 2015-09-07
- 1.0.12 — 2015-09-06
- 1.0.11 — 2015-09-06
- … 11 more at https://npm.io/package/halt/versions

## README

Halt
====
Halt is a node addon that makes it possible for the user to stop the execution of a V8 instance without kill the current loop.<br/>
Timeouts are managed by creating a parallel event loop who's sole objective is to manage the timer.<br/>
When a program is bottlenecked by the CPU, you may want to kill this event and that is the reason why we throw a nice CPU bound Exception on timeout.

Installation
------------
``` 
npm install halt
```

Compatibility
------
From node 0.12 - node 9 included<br/>
iojs 3

Timer
-------
When an engine is busy, a program needs more time to end but consumes the same amount of cpu ticks.<br/>
In this case we would like to give more time to this program to end his execution while he doesn't consume too many cpu ticks.<br/>
That's why the timer will be restarted until the maximum amount of cpu ticks is reached or the program ends his execution.<br/>
This maximum is determined by the value send to halt.start/run() and the cpu ticks per millisecond which is configurable and has 1000 as default value.

Usage
-----
You can either kill the javascript executing thread by 
* starting a timer on a function with halt.run()
* manually calling start, protect and clear on the halt module
```javascript
var halt = require('halt')
halt.ticksPerMsec = 1010;

function goFetchSomeMilk () { /* ... */; return milk; }

// In this case, max cpu ticks = 1000 * 60 * 10 * 1010;
// If max cpu ticks is reached, stop waiting

// Automatic managing
halt.run(goFetchSomeMilk, 1000 * 60 * 10)
 
// Manually managing
halt.start(1000 * 60 * 10);
halt.protect(goFetchSomeMilk);
halt.clear();
```

Exception
-------
When execution is forcefully terminated using TerminateExecution(), a catchable exception is generated.<br/>
In case you have sensible code and you want to recover the exception and catch it, you can use:
```javascript
var halt = require('halt')

function goFetchSomeMilk () { /* ... */; return milk; }

try{
    halt.start(50);
    try{
        halt.protect(goFetchSomeMilk);
    }
    catch(){
        /* What ever you want */
    }
    halt.clear();
}
```

License
-------
![alt cc](https://licensebuttons.net/l/by/3.0/88x31.png)
This work is licensed under a [Creative Commons Attribution 4.0 International License] (http://creativecommons.org/licenses/by/4.0/)

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