-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: async-ify all the depgraph builder functions
- Loading branch information
1 parent
5a67037
commit 6f7da8a
Showing
13 changed files
with
115 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as pMap from 'p-map'; | ||
import { eventLoopSpinner } from 'event-loop-spinner'; | ||
|
||
/** Run a function each element in an array, with some level of concurrency. | ||
* | ||
* Defaults to a small, finite concurrency, so as to not to "overload" the database | ||
* connection pool or the http client, both of which have small, internal limits. | ||
* | ||
* Can be used with async functions that don't yield; will yield for you, if necessary. | ||
*/ | ||
export async function cMap<F, T>( | ||
input: Iterable<F>, | ||
mapper: (from: F) => Promise<T>, | ||
options?: { concurrency: number }, | ||
): Promise<T[]> { | ||
const concurrency = options?.concurrency ?? 6; | ||
return await pMap( | ||
input, | ||
async (from) => { | ||
if (eventLoopSpinner.isStarving()) { | ||
await eventLoopSpinner.spin(); | ||
} | ||
return await mapper(from); | ||
}, | ||
{ concurrency }, | ||
); | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.