saghul / txiki.js

A tiny JavaScript runtime
MIT License
2.37k stars 157 forks source link

core: refactor signal handling #480

Closed saghul closed 1 month ago

saghul commented 1 month ago

Replace the current signal API with one following a similar model to EventTarget, a la Deno.

Before

const sh = tjs.signal('SIGINT', handleSigInt);
// sh needs to be alive or the signal handler is destroyed.

After

tjs.addSignalListener('SIGINT', handleSigInt);
// No need to use a handle, it can be removed with
// tjs.removeSignalListener.

Fixes: https://github.com/saghul/txiki.js/issues/476 Ref: https://github.com/saghul/txiki.js/issues/477