Would it be possible to add setTimeout-equivalent function to JS shell?




2 years ago
a year ago


(Reporter: arai, Unassigned)




Firefox Tracking Flags

(Not tracked)




2 years ago
while testing Promise, async functions, and async generators, sometimes I want to use timer in test script (not for automated test tho).
would it be possible to add setTimeout or similar thing to JS shell so that we can test such cases in shell?

main concern is that JS shell version of setTimeout might behave differently than DOM setTimeout...
Presumably what you are looking for is a function that does "run this code when there are no promises pending"?

This doesn't seem too hard to implement in the abstract, mostly the shell main program becomes a loop with a deadline-sorted list of callbacks instead of the straight-line code it already is.

(BTW, it is my understanding that both V8 and Chakra have more DOM-like interfaces in their JS shells - Worker objects, postMessage channels.  It's possible we should think about moving in that direction too, to allow simpler testing.)

Comment 2

2 years ago
yeah, indeed, it's not required to wait long time, but just execute the function (or just resolve the Promise) in specified order, after performing all pending jobs.

I'll look into that direction, and also V8/Chakra shells' implementation.
Keywords: triage-deferred
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.