1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/睡眠函数 [sleep].html

33 lines
755 B
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>请你编写一个异步函数,它接收一个正整数参数 <code>millis</code>&nbsp;,并休眠 <code>millis</code> 毫秒。要求此函数可以解析任何值。</p>
<p>&nbsp;</p>
<p><b>示例 1</b></p>
<pre>
<b>输入:</b>millis = 100
<b>输出:</b>100
<b>解释:</b>
在 100ms 后此异步函数执行完时返回一个 Promise 对象
let t = Date.now();
sleep(100).then(() =&gt; {
console.log(Date.now() - t); // 100
});
</pre>
<p><b>示例 2</b></p>
<pre>
<b>输入:</b>millis = 200
<b>输出:</b>200
<b>解释:</b>在 200ms 后函数执行完时返回一个 Promise 对象
</pre>
<p>&nbsp;</p>
<p><b>提示:</b></p>
<ul>
<li><code>1 &lt;= millis &lt;= 1000</code></li>
</ul>