-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1324 from NASA-AMMOS/improve-large-expansion-sets
Improve large expansion sets
- Loading branch information
Showing
6 changed files
with
155 additions
and
50 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export class PromiseThrottler { | ||
private runningPromises: Promise<unknown>[] = []; | ||
private promiseLimit: number; | ||
|
||
public constructor(promiseLimit: number) { | ||
this.promiseLimit = promiseLimit; | ||
} | ||
|
||
public async run<T>(promiseFactory: () => Promise<T>): Promise<T> { | ||
while (this.runningPromises.length >= this.promiseLimit) { | ||
await Promise.race(this.runningPromises); | ||
} | ||
const promise = promiseFactory(); | ||
this.runningPromises.push(promise); | ||
return promise.finally(() => { | ||
const index = this.runningPromises.indexOf(promise); | ||
if (index !== -1) { | ||
this.runningPromises.splice(index, 1); | ||
} | ||
}); | ||
} | ||
} |
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