Created
November 10, 2022 18:49
-
-
Save malero/f4ae32b070f9e654a8785aa30eac93b8 to your computer and use it in GitHub Desktop.
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
class Runner { | |
public readonly targetRequests: number; | |
private _requests = 0; | |
constructor(targetRequests: number) { | |
this.targetRequests = targetRequests; | |
} | |
public async run(): Promise<void> { | |
while (this._requests < this.targetRequests) { | |
await invoke(); | |
this._requests++; | |
} | |
} | |
public static async run(targetRequests: number): Promise<Runner> { | |
const runner = new Runner(targetRequests); | |
await runner.run(); | |
return runner; | |
} | |
} | |
const promises = []; | |
const runners: number = 100; | |
const requestsPerRunner: number = 100; | |
for (let i = 0; i < 10; i++) { | |
promises.push(Runner.run(requestsPerRunner)) | |
} | |
await Promise.all(promises); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment