Skip to content

Commit 8cb0576

Browse files
committed
refactor: export signals() function for public API access
Previously signals() was an internal getSignals() function. Now it's exported to allow external code to query the list of signals being monitored.
1 parent 8ee7846 commit 8cb0576

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

src/signal-exit.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function getSignalListeners() {
105105
if (_sigListeners === undefined) {
106106
_sigListeners = { __proto__: null } as unknown as SignalListenerMap
107107
const emitter = getEmitter()
108-
const sigs = getSignals()
108+
const sigs = signals()
109109
for (const sig of sigs) {
110110
_sigListeners[sig] = function listener() {
111111
// If there are no other listeners, an exit is coming!
@@ -128,33 +128,6 @@ function getSignalListeners() {
128128
return _sigListeners as SignalListenerMap
129129
}
130130

131-
let _signals: string[] | undefined
132-
/*@__NO_SIDE_EFFECTS__*/
133-
function getSignals() {
134-
if (_signals === undefined) {
135-
_signals = ['SIGABRT', 'SIGALRM', 'SIGHUP', 'SIGINT', 'SIGTERM']
136-
if (!WIN32) {
137-
_signals.push(
138-
'SIGVTALRM',
139-
'SIGXCPU',
140-
'SIGXFSZ',
141-
'SIGUSR2',
142-
'SIGTRAP',
143-
'SIGSYS',
144-
'SIGQUIT',
145-
'SIGIOT',
146-
// should detect profiler and enable/disable accordingly.
147-
// see #21
148-
// 'SIGPROF'
149-
)
150-
}
151-
if (platform === 'linux') {
152-
_signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT', 'SIGUNUSED')
153-
}
154-
}
155-
return _signals as string[]
156-
}
157-
158131
/*@__NO_SIDE_EFFECTS__*/
159132
function emit(event: string, code: number | null, signal: string | null): void {
160133
const emitter = getEmitter()
@@ -188,7 +161,7 @@ export function load(): void {
188161
emitter.count += 1
189162
}
190163

191-
const sigs = getSignals()
164+
const sigs = signals()
192165
const sigListeners = getSignalListeners()
193166
_signals = sigs.filter(sig => {
194167
try {
@@ -297,12 +270,34 @@ export function onExit(
297270
}
298271
}
299272

273+
let _signals: string[] | undefined
300274
/**
301275
* Get the list of signals that are currently being monitored.
302276
*/
303277
/*@__NO_SIDE_EFFECTS__*/
304-
export function signals(): string[] | undefined {
305-
return _signals
278+
export function signals() {
279+
if (_signals === undefined) {
280+
_signals = ['SIGABRT', 'SIGALRM', 'SIGHUP', 'SIGINT', 'SIGTERM']
281+
if (!WIN32) {
282+
_signals.push(
283+
'SIGVTALRM',
284+
'SIGXCPU',
285+
'SIGXFSZ',
286+
'SIGUSR2',
287+
'SIGTRAP',
288+
'SIGSYS',
289+
'SIGQUIT',
290+
'SIGIOT',
291+
// should detect profiler and enable/disable accordingly.
292+
// see #21
293+
// 'SIGPROF'
294+
)
295+
}
296+
if (platform === 'linux') {
297+
_signals.push('SIGIO', 'SIGPOLL', 'SIGPWR', 'SIGSTKFLT', 'SIGUNUSED')
298+
}
299+
}
300+
return _signals as string[]
306301
}
307302

308303
/**
@@ -315,7 +310,7 @@ export function unload(): void {
315310
}
316311
loaded = false
317312

318-
const sigs = getSignals()
313+
const sigs = signals()
319314
const sigListeners = getSignalListeners()
320315
for (const sig of sigs) {
321316
try {

0 commit comments

Comments
 (0)