Gathering detailed insights and metrics for xflight
Gathering detailed insights and metrics for xflight
Gathering detailed insights and metrics for xflight
Gathering detailed insights and metrics for xflight
npm install xflight
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
8 Commits
1 Branches
1 Contributors
Updated on Jun 03, 2025
Latest Version
2.0.2
Package Id
xflight@2.0.2
Unpacked Size
21.88 kB
Size
4.93 kB
File Count
12
NPM Version
11.3.0
Node Version
24.1.0
Published on
Jun 03, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
7
Avoid redundant async calls by sharing inflight promises for the same key.
xflight
is a lightweight Node.js utility that manages inflight promises by key. It ensures that only one asynchronous operation per key is running at a time, returning the same promise for concurrent requests. This is useful for avoiding duplicate network or resource-intensive calls.
1npm install xflight
This package requires Node.js >= 20.
1const Xflight = require("xflight"); 2const xfl = new Xflight(); 3 4function fetchData(url) { 5 return xfl.promise(url, () => fetch(url)); 6} 7 8// Multiple calls with the same URL will share the same promise if still pending 9fetchData("https://api.example.com/data").then(console.log); 10fetchData("https://api.example.com/data").then(console.log);
1import Inflight from "xflight"; 2 3const inflight = new Inflight(); 4const key = "resource-1"; 5 6// Deduplicate async calls 7const resultPromise = inflight.promise(key, () => fetch("https://api.example.com/data"));
1const Inflight = require("xflight").default; 2 3const inflight = new Inflight(); 4// ... use as shown in examples above
new Xflight([PromiseImpl])
PromiseImpl
(optional): Custom Promise implementation (e.g., Bluebird, Aveazul, or native Promise).Note: By default, the constructor will try to use Bluebird or Aveazul as the Promise implementation if they are available. If you want to always use the native Promise and skip these checks, pass the global Promise as the argument:
1const inflight = new Inflight(Promise);
promise(key, promiseFactory)
key
: Unique identifier for the inflight operation.promiseFactory
: Function that returns a promise.promiseFactory
, or the existing inflight promise for the key.add(key, value, [now])
value
should be a promise.get(key)
undefined
.remove(key)
isEmpty
count
getStartTime(key)
: Get start time (ms since epoch) for a key.time(key, [now])
/ elapseTime(key, [now])
: Elapsed time since start.getCheckTime(key)
: Get last check time for a key.lastCheckTime(key, [now])
/ elapseCheckTime(key, [now])
: Elapsed time since last check.resetCheckTime(key, [now])
: Reset last check time to now.To run tests:
1npm test
Test coverage is enforced at 100% using nyc
.
promise
1import Inflight from "xflight"; 2 3const inflight = new Inflight(); 4const key = "resource-1"; 5 6// Deduplicate async calls 7const resultPromise = inflight.promise(key, () => fetch("https://api.example.com/data")); 8// or, for clarity: 9const resultPromise2 = inflight.promise(key, function promiseFactory() { 10 return fetch("https://api.example.com/data"); 11});
1const promise = new Promise((resolve) => setTimeout(() => resolve("done"), 100)); 2inflight.add("manual-key", promise); 3const inflightPromise = inflight.get("manual-key"); // Promise<string> | undefined
1inflight.remove("manual-key");
1console.log(inflight.isEmpty); // true or false 2console.log(inflight.count); // number of inflight items
1inflight.add("timed-key", new Promise(() => {})); 2const start = inflight.getStartTime("timed-key"); 3const elapsed = inflight.time("timed-key"); 4const elapsedAlias = inflight.elapseTime("timed-key");
1const check = inflight.getCheckTime("timed-key"); 2const sinceLastCheck = inflight.lastCheckTime("timed-key"); 3const sinceLastCheckAlias = inflight.elapseCheckTime("timed-key");
1// Reset for a specific key 2inflight.resetCheckTime("timed-key"); 3// Reset for all inflight items 4inflight.resetCheckTime();
Apache-2.0
© Joel Chen
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More