Skip to main content

Wait

Description​

Wait is a custom util designed to pause the execution of a code for a specified duration.


Integration and Usage​

To use scriptLoader util, you need to import it into your project

import { wait } from './path/to/utils/wait';

and call the function wait where you want a delay to happen.

await wait();


Wait Function​

export async function wait(duration = 10): Promise<void>

Parameters​

  • duration: number
    • duration of the wait in milliseconds
    • default is set to 10 milliseconds

Return Type​

  • Promise<void>
    • resolves after the specified duration, enabling the use of await function to pause code execution


Function Logic​

script.onload = () => resolve(script);
script.onerror = () => reject(new Error(`Script load error for ${src}`));

Event listeners are added to the script, waiting to either resolve the promise if the script is successfully loaded or reject it.



Events​

This util does not have any events.