-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (35 loc) · 952 Bytes
/
Copy pathindex.ts
File metadata and controls
37 lines (35 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* # 2621. Sleep
* @link [LeetCode](https://leetcode.com/problems/sleep/description/)
*
* @description
* Given a positive integer millis, write an asynchronous function that sleeps for millis milliseconds. It can resolve any value.
*
* Note that minor deviation from millis in the actual sleep duration is acceptable.
*
* Constraints:
* - 1 <= millis <= 1000
*
* @example sleep(100);
* Output: 100
* It should return a promise that resolves after 100ms.
* let t = Date.now();
* sleep(100).then(() => {
* console.log(Date.now() - t); // 100
* });
*
* @example sleep(200);
* Output: 200
* It should return a promise that resolves after 200ms.
*
* @param {number} millis
* @returns {Promise<void>}
*/
async function sleep(millis: number): Promise<void> {
return new Promise((res) => setTimeout(res, millis));
}
/**
* let t = Date.now()
* sleep(100).then(() => console.log(Date.now() - t)) // 100
*/
export { sleep };