JavaScript waitForTime
I write a lot of tests for new features within Firefox DevTools. We have hundreds of "mochitests" which open the browser and perform synthetic actions like clicking, typing, and other user actions. I've previously written about waitForever
which essentially halts following actions without locking the browser. Another utility I enjoy is waitForTime
, an async JavaScript function that I can await
to give breathing time between two tasks.
Whenever I want to wait a given amount of time between tasks, I employ this function:
function waitForTime(ms) {
return new Promise(r => setTimeout(r, ms));
}
/* Usage */
await waitForTime(200);
// ...do other thing...
await waitForTime(200);
// ...do next thing ...
It's important to point out that most waitForTime
calls don't appear in the final test, since arbitrary timeouts lead to intermittent test failures, but they are helpful in knowing where I need to add polling for some other condition!
Two years ago I documented my struggles with Imposter Syndrome and the response was immense. I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions. I've even caught myself reading the post...
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API.
Every once in a while I find a tiny JavaScript library that does something very specific, very well. My latest find, Fokus, is a utility that listens for text selection within the page, and when such an event occurs, shows a beautiful modal dialog in...
I released my first MooTools class over a year ago. It was a really minimalistic approach to zebra tables and a great first class to write. I took some time to update and improve the class.
The XHTML
You may have as many tables as...
I have this kind of a function in all my apps and I usually name is delay.
You don’t have to put “async” in front of the function?