Skip to content

Instantly share code, notes, and snippets.

@scripting
Created May 12, 2026 21:28
Show Gist options
  • Select an option

  • Save scripting/b3c361f25d6d2fb9a872082c8fd30439 to your computer and use it in GitHub Desktop.

Select an option

Save scripting/b3c361f25d6d2fb9a872082c8fd30439 to your computer and use it in GitHub Desktop.
This code was coming up all over the place and I wanted to make it easy to find.
function addFeedsIfNecessary (urlsToCheck, callback) {
const ctTotalFeeds = urlsToCheck.length;
var ixNext = 0, ctInFlight = 0, ctDone = 0;
function startMore () {
while (true) {
if (ctInFlight >= config.maxConcurrentFeedChecks) {
break;
}
if (ixNext >= ctTotalFeeds) {
break;
}
const url = urlsToCheck [ixNext++];
ctInFlight++;
addFeedIfNecessary (url, function (err) {
ctInFlight--;
if (++ctDone >= ctTotalFeeds) {
callback ();
}
else {
startMore ();
}
});
}
}
if (ctTotalFeeds > 0) {
startMore ();
}
else {
callback ();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment