Skip to content

fix: ref() and unref() return this to align with NodeJS Timeout api#10

Open
TillaTheHun0 wants to merge 1 commit into
tellnes:masterfrom
TillaTheHun0:master
Open

fix: ref() and unref() return this to align with NodeJS Timeout api#10
TillaTheHun0 wants to merge 1 commit into
tellnes:masterfrom
TillaTheHun0:master

Conversation

@TillaTheHun0
Copy link
Copy Markdown

Thank you for your work on this module!

Background

NodeJS' Timeout.ref() and Timeout.unref() both return a reference to the Timeout.

This allows for doing things like:

const timeout = setTimeout(() => {}, 100).unref()

// later
clearTimeout(timeout)

instead of having to call timeout.unref() as a separate expression.

Problem

Since long-timeout's impls of ref() and unref() return undefined, the above usage will result in unexpected behavior -- the timeout is never cleared and will later be invoked (clearTimeout will simply noop, if passed anything that is not a timeout)

Changes

This PR updates ref() and unref() on Timeout and Interval to return this, such to match NodeJS' api and get long-timeout closer to a drop-in replacement (at least w.r.t ref() and unref())

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