引入
ts
import { sleep } from 't-comm';
// 不支持 tree-shaking 的项目
import { sleep} from 't-comm/lib/sleep/index';
// 只支持 ESM 的项目
import { sleep} from 't-comm/es/sleep/index';
sleep(ms)
描述:
等待一段时间
参数:
参数名 | 类型 | 描述 |
---|---|---|
ms | number | 毫秒 |
返回:
Promise
示例
typescript
async function main() {
await sleep(2000)
// 等待2秒后才会打印
console.log('hello')
}
main()