{ "data": { "question": { "questionId": "2733", "questionFrontendId": "2621", "categoryTitle": "JavaScript", "boundTopicId": 2222274, "title": "Sleep", "titleSlug": "sleep", "content": "
Given a positive integer millis
, write an asynchronous function that sleeps for millis
milliseconds. It can resolve any value.
\n
Example 1:
\n\n\nInput: millis = 100\nOutput: 100\nExplanation: It should return a promise that resolves after 100ms.\nlet t = Date.now();\nsleep(100).then(() => {\n console.log(Date.now() - t); // 100\n});\n\n\n
Example 2:
\n\n\nInput: millis = 200\nOutput: 200\nExplanation: It should return a promise that resolves after 200ms.\n\n\n
\n
Constraints:
\n\n1 <= millis <= 1000
请你编写一个异步函数,它接收一个正整数参数 millis
,并休眠 millis
毫秒。要求此函数可以解析任何值。
\n\n
示例 1:
\n\n\n输入:millis = 100\n输出:100\n解释:\n在 100ms 后此异步函数执行完时返回一个 Promise 对象\nlet t = Date.now();\nsleep(100).then(() => {\n console.log(Date.now() - t); // 100\n});\n\n\n
示例 2:
\n\n\n输入:millis = 200\n输出:200\n解释:在 200ms 后函数执行完时返回一个 Promise 对象\n\n\n
\n\n
提示:
\n\n1 <= millis <= 1000
\\u7248\\u672c\\uff1a \\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\" TypeScript 5.1.6<\\/p>\\r\\n\\r\\n Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "100\n200",
"__typename": "QuestionNode"
}
}
}Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n
--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n