long-timeout
long-timeout copied to clipboard
fix: ref() and unref() return this to align with NodeJS Timeout api
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()
)