Created
May 12, 2026 21:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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