# inflight 中文文档

规范地址：https://npmcn.com/package/inflight/

版本：1\.0\.6
npm 元数据更新时间：2024-05-23T03:14:32.244Z
中文译文更新时间：2026-11-05T15:13:28.382Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/inflight
原文对照：https://npmcn.com/package/inflight/?lang=original
项目主页：https://github.com/isaacs/inflight
源码仓库：https://github.com/npm/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\.

## 关键信息（来自 npm 元数据）

- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：2 个
- 首次发布：2014-05-05T03:04:32.021Z
- 最新版本发布：2016-10-13T03:53:29.524Z
- 近 30 天下载量：428260428（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install inflight
```

也可以使用：`pnpm add inflight`、`yarn add inflight`、`bun add inflight`

## README

# 飞行

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

## 用户

```javascript
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 是什么？

在飞行中的请求中添加回调以避免重复注意：该包已被作者标记为弃用——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。作者已将其标记为弃用，新项目建议寻找替代方案。

