This repository was archived by the owner on Nov 2, 2025. It is now read-only.
refactor: use setTimeout from timers module#43
Open
bartlomieju wants to merge 3 commits intotapjs:mainfrom
Open
refactor: use setTimeout from timers module#43bartlomieju wants to merge 3 commits intotapjs:mainfrom
bartlomieju wants to merge 3 commits intotapjs:mainfrom
Conversation
Member
|
This is a good change, I'm happy to support Deno. I think you'll have to pull in The easiest way to test this would be to mock the // somewhere in test/base.js
const { setTimeout, clearTimeout } = require('timers')
const mockTimers = {
timeoutsSet: [],
timeoutsCleared: [],
setTimeout: (fn, time) => {
const handle = setTimeout(fn, time)
timeoutsSet.push([handle, fn, time])
return handle
},
clearTimeout: (handle) => {
const ret = clearTimeout(handle)
timeoutsCleared.push(handle)
return ret
}
}
const Base = t.mock('../lib/base.js', { timers: mockTimers })
const b = new Base({name: 'timer mock test'})
b.setTimeout(1000)
b.setTimeout(0)
// now verify that mockTimers.timeoutsSet and mockTimers.timeoutsCleared
// contain some entries, that they're what you expect, etc. |
Author
|
Thanks for pointers @isaacs, I added a test. Let me know if there's anything else I should do. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A small change that uses
setTimeoutfromtimersmodule instead of relying on a global.I'm trying to get
taprunning in Deno's Node.js compat mode and return types forsetTimeoutandsetIntervalare fundamentally incompatible - Deno follow's Web APIs and returns a number, while Node.js returns and object that allows to ref/unref the timer. AFAIK there's no other way to unref a timer in Node.js and this is one of the incompatibilities we haven't yet figured out how to handle nicely. UsingsetTimeoutfromtimersmodule allows us to polyfill that API properly without changing return types on built-in globals.I'm not really sure how we could test this change, suggestions are appreciated.