Ghost/ghost/core/test/utils/sleep.js
Naz e170f293e3
Extracted sleep method to e2e framework module
no issue

- The sleep method has been used in 8 modules reimplementing the same thing over and over again. It's usually a sign of async event processing outside of the request/response loop. It's good to have a single point of implementation for a "hack" like this, so we could track it easier and address the even processing delay in a more optimal way centrally if it ever becomes a bottleneck
2022-12-05 17:26:29 +07:00

16 lines
497 B
JavaScript

/**
* Adds artificial "sleep" time that can be awaited
* In most cases where this module is used we are awaiting
* for the async event processing to trigger/finish
*
* Can probably be substituted by timerPromises in the future
* ref.: https://nodejs.org/dist/latest-v18.x/docs/api/timers.html#timerspromisessettimeoutdelay-value-options
* @param {number} ms
* @returns {Promise<void>}
*/
module.exports = ms => (
new Promise((resolve) => {
setTimeout(resolve, ms);
})
);