hapijs / hoek

Node utilities shared among the extended hapi universe
Other
480 stars 171 forks source link

Add a wait() method #206

Closed kanongil closed 7 years ago

kanongil commented 7 years ago

With domain support going away in Hapi, an errant throw inside a setTimeout() will cause the uncaughtException event to be emitted. This can be mitigated by awaiting on a delay() method:

const delay = function (duration) {

    return new Promise((resolve) => setTimeout(resolve, duration));
};

This will change something like:

setTimeout(() => {
    /* my delayed code */
), 100);

to:

await delay(100);
/* my delayed code */
hueniverse commented 7 years ago

For now, I am writing these utilities locally where needed. As v17 gets more mature, we will collect these utils and put them here. I've been writing await internal.wait(100) quite a bit...

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.