I wrote a utility function to create an async timeout:
export function asyncTimeout(timeout: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, timeout))
}
I also wrote a unit test in vitest:
test('asyncTimeout', async ()=> {
const start = Date.now()
await asyncTimeout(10)
const end = Date.now()
expect(end - start).toBeGreaterThanOrEqual(10)
})
Most of the time this test passes. But sometimes it fails:
How is that possible? Is it possible that setTimeout fires earlier than the specified time?

process.hrtimeorprocess.hrtime.bigintprocess.hrtime.bigintit gave me 15ms delay which is greater than expected 10ms