Lodash _.delay() Method
Last Updated :
31 Oct, 2023
Lodash _.delay() method is used to call the given function as the parameter after the stated wait time is over, which is in milliseconds. Any further arguments are provided to the function when it is called.
Syntax:
_.delay(func, wait, args);
Parameters:
- func: It is the function that has to be delayed.
- wait: It is the number of milliseconds for which the function call is delayed.
- args: It is the arguments with which the given function is being called. It is an optional parameter.
Return Value:
This method returns the timer id.
Example 1: In this example, the content is printed after the delay of 3 seconds as the wait time is 3 seconds.
Javascript
const _ = require( 'lodash' );
_.delay( function (content) {
console.log(content);
}, 3000, 'GeeksforGeeks!' );
console.log( 'Content:' );
|
Output:
Content:
GeeksforGeeks!
Example 2: In this example, each integer is printed after a delay of 2 seconds.
Javascript
const _ = require( 'lodash' );
let func = number => {
console.log(number);
};
for (let i = 1; i <= 5; i++) {
_.delay(func, 2000 * (i + 1), i);
}
console.log( 'Integers are as follows:' );
|
Output:
Integers are as follows:
1
2
3
4
5
Share your thoughts in the comments
Please Login to comment...