Sitelet https://github.com/node-cron/node-cron/pull/620
Skip to content

fix: preserve once listeners in inline tasks - #620

Open
bensynapse wants to merge 1 commit into
node-cron:mainfrom
bensynapse:fix-once-listeners
Open

bensynapse wants to merge 1 commit into
node-cron:mainfrom
bensynapse:fix-once-listeners

Conversation

@bensynapse

Copy link
Copy Markdown

I run Live Tennis API.

task.once('execution:finished', callback) currently fires for every execution and leaves its listener registered. The inline dispatcher calls listeners(), which unwraps once listeners.

Dispatch rawListeners() with the EventEmitter receiver. This restores once cleanup and normal listener binding while keeping synchronous and async listener errors isolated.

Five regression tests fail before the fix. npm run check passes all 758 tests on Node 22. The suite also passes on Node 20 and 24, and Node 22 with TZ=America/Sao_Paulo.

npm run typecheck and npm run build pass. Built ESM and CommonJS checks pass, including real background executions.

For the background checks I called stop() before destroy(). Direct CommonJS destroy() can time out on both main and this branch.

Calling EventEmitter.listeners() skips the wrapper that removes once
listeners. Invoke raw listeners with their emitter receiver so callbacks
run once and retain their usual binding. Keep listener error capture.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant