@cs125/wait-until

中文文档
0.0.3发布于 2018/07/23MITCommonJS零依赖近 30 天下载 3220

Simple library to wait until a condition has been satisfied.

原始使用文档
文档目录4 节
  1. Usage
  2. Fluent interface
  3. Async conditions
  4. Other notes

wait-until Build status npm package

This simple Node.js module provides a way to check for a condition every so often, then run a callback after the condition is met or the allotted time expires.

This is good if you need to wait for specific state changes in code that you don't have direct control over, like a headless web browser.

Usage

var waitUntil = require('wait-until');

waitUntil(interval, times, function condition() {
    return (someCondition ? true : false);
}, function done(result) {
    // result is true on success or false if the condition was never met
});

The condition function will be called up to times times, starting after interval milliseconds. Once it returns true (or a truthy value), the done callback will be called with result equal to true (or whatever value the condition function returned).

If the condition is never met within the specified timeframe, done will be called with result equal to false (or whatever falsy value the condition function returned the last time it was called).

Fluent interface

Don't want to remember the order of arguments? Then use the fluent interface:

var waitUntil = require('wait-until');

waitUntil()
    .interval(500)
    .times(10)
    .condition(function() {
        return (someCondition ? true : false);
    })
    .done(function(result) {
        // do stuff
    });

Async conditions

If the condition function accepts an argument, then it is assumed to be a callback function which will be called with the result of the test:

var waitUntil = require('wait-until');

waitUntil()
    .interval(500)
    .times(10)
    .condition(function(cb) {
        process.nextTick(function() {
            cb(someCondition ? true : false);
        });
    })
    .done(function(result) {
        // do stuff
    });

Other notes

You can specify .times(Infinity) if you like, but it's probably better to set and enforce a reasonable timeout.

版本与发布记录

@cs125/wait-until 共发布 1 个版本,首次发布于 2018/07/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.3latest2018/07/238 年前

关于 @cs125/wait-until 的常见问题

@cs125/wait-until 是什么?

Simple library to wait until a condition has been satisfied.

如何安装 @cs125/wait-until?

在项目目录运行 npm install @cs125/wait-until,或使用 pnpm add / yarn add / bun add。

@cs125/wait-until 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cs125__wait-until 是否存在。

@cs125/wait-until 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cs125/wait-until 可以商用吗?

@cs125/wait-until 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cs125/wait-until 的下载量有多少?

根据 npm 官方下载统计,@cs125/wait-until 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,220 次,日均约 107 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cs125/wait-until 还在维护吗?

最新版本 0.0.3 发布于 2018/07/23(8 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/07/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。