inflight

中文文档
1.0.6发布于 2016/10/13ISCCommonJS近 30 天下载 4.3亿

在飞行中的请求中添加回调以避免重复

此软件包已被标记为弃用

This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.

中文使用文档

飞行

在飞行中的请求中添加回调以避免重复

用户

var inflight = require('inflight')

// some request that does some stuff
function req(key, callback) {
  // key is any random string.  like a url or filename or whatever.
  //
  // will return either a falsey value, indicating that the
  // request for this key is already in flight, or a new callback
  // which when called will call all callbacks passed to inflightk
  // with the same key
  callback = inflight(key, callback)

  // If we got a falsey value back, then there's already a req going
  if (!callback) return

  // this is where you'd fetch the url or whatever
  // callback is also once()-ified, so it can safely be assigned
  // to multiple events etc.  First call wins.
  setTimeout(function() {
    callback(null, key)
  }, 100)
}

// only assigns a single setTimeout
// when it dings, all cbs get called
req('foo', cb1)
req('foo', cb2)
req('foo', cb3)
req('foo', cb4)

版本与发布记录

inflight 共发布 7 个版本,首次发布于 2014/05/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.6latest2016/10/1310 年前
1.0.52016/05/1810 年前
1.0.42014/10/0312 年前
1.0.32014/10/0212 年前
1.0.22014/09/1912 年前
1.0.12014/05/0612 年前

关于 inflight 的常见问题

inflight 是什么?

在飞行中的请求中添加回调以避免重复注意:该包已被作者标记为弃用——This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.

如何安装 inflight?

在项目目录运行 npm install inflight,或使用 pnpm add / yarn add / bun add。

inflight 支持 TypeScript 吗?

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

inflight 支持 ESM 还是 CommonJS?

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

inflight 可以商用吗?

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

inflight 的下载量有多少?

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

inflight 还在维护吗?

最新版本 1.0.6 发布于 2016/10/13(10 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2014/05/05。作者已将其标记为弃用,新项目建议寻找替代方案。