Sleep
A utility function to pause execution for a specified duration. This function is part of the Utilities provided by the DID Spaces SDK.
Usage#
The sleep
utility function allows you to introduce a delay in your asynchronous operations. It takes a single argument, the duration in milliseconds, and returns a Promise that resolves after the specified time.
Parameters
Name | Type | Description |
---|---|---|
|
| The duration in milliseconds to pause execution. |
Returns
Name | Type | Description |
---|---|---|
|
| A Promise that resolves after the specified duration, indicating the pause is complete. |
Example
import { sleep } from '@arcblock/did-spaces-client';
async function delayedOperation() {
console.log('Starting operation...');
await sleep(2000); // Pause for 2 seconds
console.log('Operation resumed after 2 seconds.');
console.log('Performing another task...');
await sleep(500); // Pause for 0.5 seconds
console.log('Another task completed.');
}
delayedOperation();
This example demonstrates how to use sleep
to pause the execution of an async
function for a specified number of milliseconds, allowing for controlled delays in your application flow.
This section concludes the documentation for the utility functions. To learn more about the core capabilities of the DID Spaces SDK, you can explore the Commands Reference or return to the Overview of the SDK.