mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
e170f293e3
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
16 lines
497 B
JavaScript
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);
|
|
})
|
|
);
|