Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
yieldy-for-loop
Advanced tools
A small utility to process large loops without blocking the main thread
A tiny utility to process large loops in a non-blocking way by yielding periodically, ensuring your UI stays responsive even under heavy iteration.
Inspired by “Breaking up with long tasks, or how I learned to group loops and wield the yield” (PerfPlanet 2024).
requestAnimationFrame
and a small timeout race.scheduler.yield()
when available.npm install yieldy-for-loop
import yieldyForLoop from "yieldy-for-loop";
const items = Array.from({ length: 100000 }, (_, i) => i);
function processItem(item) {
// Your heavy computation
console.log("Processing item:", item);
}
(async function main() {
console.log("Starting yieldy loop...");
await yieldyForLoop(items, processItem, {
fps: 30, // optional, default is 30
hiddenThreshold: 500 // optional, default is 500
});
console.log("Done processing!");
})();
yieldyForLoop<T>(
items: Iterable<T>,
processFn: (item: T) => void,
options?: {
fps?: number; // default 30
hiddenThreshold?: number; // default 500 ms
}
): Promise<void>;
Parameters:
fps
(number): Target frames per second; used to calculate how long each batch can run before yielding.hiddenThreshold
(number): Yield threshold (in ms) if the document is hidden.BATCH_DURATION
from the desired FPS (e.g., 30 FPS = 33 ms).setTimeout
to yield.scheduler.yield()
) if available.processFn
.When you have long-running loops—like processing large arrays or performing expensive computations on each iteration—the main thread can get blocked, causing the UI to freeze. By periodically yielding control to the browser, you let the UI stay responsive, handle user interactions, and remain smooth.
Contributions, issues, and feature requests are welcome! Feel free to open an issue or pull request on GitHub.
FAQs
A small utility to process large loops without blocking the main thread
We found that yieldy-for-loop demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.