mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
74 lines
1.1 KiB
Markdown
74 lines
1.1 KiB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
|
|
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [sleep](./bitburner.ns.sleep.md)
|
|
|
|
## NS.sleep() method
|
|
|
|
Suspends the script for n milliseconds.
|
|
|
|
**Signature:**
|
|
|
|
```typescript
|
|
sleep(millis?: number): Promise<true>;
|
|
```
|
|
|
|
## Parameters
|
|
|
|
<table><thead><tr><th>
|
|
|
|
Parameter
|
|
|
|
|
|
</th><th>
|
|
|
|
Type
|
|
|
|
|
|
</th><th>
|
|
|
|
Description
|
|
|
|
|
|
</th></tr></thead>
|
|
<tbody><tr><td>
|
|
|
|
millis
|
|
|
|
|
|
</td><td>
|
|
|
|
number
|
|
|
|
|
|
</td><td>
|
|
|
|
_(Optional)_ Number of milliseconds to sleep. Default to 0.
|
|
|
|
|
|
</td></tr>
|
|
</tbody></table>
|
|
|
|
**Returns:**
|
|
|
|
Promise<true>
|
|
|
|
A promise that resolves to true when the sleep is completed.
|
|
|
|
## Remarks
|
|
|
|
RAM cost: 0 GB
|
|
|
|
Note that the actual delay may be longer than intended. For more information, please check [https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout\#delay](https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#delay)<!-- -->.
|
|
|
|
## Example
|
|
|
|
|
|
```js
|
|
// This will count from 1 to 10 in your terminal, with one number every 5 seconds
|
|
for (let i = 1; i <= 10; ++i) {
|
|
ns.tprint(i);
|
|
await ns.sleep(5000);
|
|
}
|
|
```
|
|
|