Nanodelay
A tiny (37 bytes) Promise wrapper around setTimeout
Install / Use
/learn @ai/NanodelayREADME
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
delaylibrary. - Has good ES modules and TypeScript support.
import { delay } from 'nanodelay'
async function foo () {
await delay(300)
// Executed after 300 milliseconds
}
delay(300).then(() => {
// Executed after 300 milliseconds
})
<a href="https://evilmartians.com/?utm_source=nanodelay">
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
alt="Sponsored by Evil Martians" width="236" height="54">
</a>
Usage
The second argument will be used in Promise as resolved value
(useful to pass variables between scopes):
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.
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.
import { setTimeout } from 'timers/promises'
await setTimeout(5000)
Related Skills
node-connect
343.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
90.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
