百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

nanodelay

> 编程语言
开源

一个非常小的(37 字节) Promise 包装器,用于围绕 setTimeout

200 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个非常小的(37 字节) Promise 包装器,用于围绕 setTimeout

Nano Delay

A tiny Promise wrapper around setTimeout for JavaScript. Returns a Promise and resolve it after a specific amount of time.

  • Only 45 bytes (minified and gzipped), 10 times smaller than delay library.
  • Has good ES modules and TypeScript support.
javascript
import { delay } from 'nanodelay'

async function foo () {
  await delay(300)
  // Executed after 300 milliseconds
}

delay(300).then(() => {
  // Executed after 300 milliseconds
})

Usage

The second argument will be used in Promise as resolved value (useful to pass variables between scopes):

javascript
createClient().then(client => {
  expect(client).toBeOK
  return delay(50, client)
}).then(client => {
  expect(client).toBeConnected()
})

For quick hacks you can load Nano Delay from CDN. Do not use it in production because of low performance.

javascript
import { delay } from 'https://cdn.jsdelivr.net/npm/nanodelay/index.js'

Future

Node.js 16+ has built-in Promise-based setTimeout. After January 2023 you can remove nanodelay from your dependencies.

javascript
import { setTimeout } from 'timers/promises'

await setTimeout(5000)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言