• Stars
    star
    187
  • Rank 206,464 (Top 5 %)
  • Language
    TypeScript
  • License
    ISC License
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

when you want to fire an event no matter how a process exits.

signal-exit

When you want to fire an event no matter how a process exits:

  • reaching the end of execution.
  • explicitly having process.exit(code) called.
  • having process.kill(pid, sig) called.
  • receiving a fatal signal from outside the process

Use signal-exit.

// Hybrid module, either works
import { onExit } from 'signal-exit'
// or:
// const { onExit } = require('signal-exit')

onExit((code, signal) => {
  console.log('process exited!', code, signal)
})

API

remove = onExit((code, signal) => {}, options)

The return value of the function is a function that will remove the handler.

Note that the function only fires for signals if the signal would cause the process to exit. That is, there are no other listeners, and it is a fatal signal.

If the global process object is not suitable for this purpose (ie, it's unset, or doesn't have an emit method, etc.) then the onExit function is a no-op that returns a no-op remove method.

Options

  • alwaysLast: Run this handler after any other signal or exit handlers. This causes process.emit to be monkeypatched.

Browser Fallback

The 'signal-exit/browser' module is the same fallback shim that just doesn't do anything, but presents the same function interface.

Patches welcome to add something that hooks onto window.onbeforeunload or similar, but it might just not be a thing that makes sense there.

More Repositories

1

tsimp

JavaScript
504
star
2

stack-utils

Captures and cleans stack traces.
JavaScript
190
star
3

tap-parser

parse the test anything protocol
121
star
4

foreground-child

Run a child as if it's the foreground process. Give it stdio. Exit when it exits.
TypeScript
40
star
5

async-hook-domain

An implementation of Domain-like error handling, built on async_hooks
JavaScript
34
star
6

tap-mocha-reporter

Format a TAP stream using Mocha's set of reporters
JavaScript
28
star
7

tmatch

This module exists to facilitate the t.match() method in node-tap (http://npm.im/tap)
22
star
8

tcompare

A comprehensive comparison library, for use in test frameworks
19
star
9

tapromise

Turn any tap Test object into a promise-resolving thingie
JavaScript
13
star
10

t-up

Tee up a test server in one file, tear it down in another
JavaScript
13
star
11

tapsert

Drop in assert replacement that produces TAP output instead of exceptions
JavaScript
11
star
12

treport

a reporter for node-tap
JavaScript
11
star
13

tt

tiny tap test thing
JavaScript
10
star
14

tapjs

monorepo for tap and friends
JavaScript
9
star
15

tsame

the logic behind tap's t.same() and t.strictSame()
6
star
16

buffer-to-string

A better Buffer.toString()
JavaScript
5
star
17

processinfo

JavaScript
5
star
18

tap-finished

detect when tap output is finished
JavaScript
5
star
19

mock-esm

JavaScript
5
star
20

libtap

A Test-Anything-Protocol library for JavaScript
JavaScript
4
star
21

tap-yaml

Yaml handling for TAP parsers and generators
4
star
22

clean-yaml-object

Clean up an object prior to serialization
JavaScript
3
star
23

core

TypeScript
3
star
24

config

TypeScript
2
star
25

tap-setup-script-example

TypeScript
2
star
26

node-test-example

JavaScript
2
star
27

ts-esm-testing

testing out making ts and esm play nice together
TypeScript
2
star
28

gh-964

TypeScript
1
star