-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
25 additions
and
3 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,22 @@ | ||
import { asyncPool, delay } from '../../src/promise'; | ||
|
||
describe('promise/asyncPool', () => { | ||
test('should be executed one by one', async function () { | ||
const pool = asyncPool({ maxConcurrency: 1 }); | ||
const start = Date.now(); | ||
pool.executor(() => delay(100)); | ||
pool.executor(() => delay(100)); | ||
await pool.executor(() => delay(100)); | ||
expect(Date.now() - start).toBeGreaterThanOrEqual(300); | ||
}); | ||
|
||
test('should be executed concurrently', async function () { | ||
const pool = asyncPool({ maxConcurrency: 3 }); | ||
const start = Date.now(); | ||
pool.executor(() => delay(100)); | ||
pool.executor(() => delay(100)); | ||
await pool.executor(() => delay(100)); | ||
// If the timer is inaccurate, add 10 to the safety range | ||
expect(Date.now() - start).toBeLessThanOrEqual(110); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
__tests__/promise.memoize.test.ts → __tests__/promise/memoize.test.ts
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
2 changes: 1 addition & 1 deletion
2
__tests__/promise.timeout.test.ts → __tests__/promise/timeout.test.ts
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