---
title: "sleep"
description: "延迟执行函数，返回一个在指定时间后 resolve 的 Promise"
seo_title: "sleep"
seo_description: "Return a promise that resolves after the given number of milliseconds, letting you pause an async flow with a simple await expression."
canonical_url: "https://core.mhaibaraai.cn/docs/utilities/async/sleep"
---
# sleep

> 延迟执行函数，返回一个在指定时间后 resolve 的 Promise

## 用法

`sleep` 函数用于延迟执行，返回一个在指定时间后 resolve 的 Promise。

```ts
import { sleep } from '@movk/core'

// 延迟1秒后继续执行
await sleep(1000)
console.log('1秒后执行')

// 在异步函数中使用
async function delayedOperation() {
  console.log('开始')
  await sleep(500)
  console.log('500ms后执行')
}
```

## API

### `sleep(ms)`

延迟执行函数，返回一个在指定时间后 resolve 的 Promise。

### 参数

**ms** (`number`) *required*: 延迟时间（毫秒）。

### 返回值

**返回值** (`Promise<void>`): 延迟 Promise。

## Changelog

See commit history for [src/utilities/async/sleep.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/utilities/async/sleep.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
