-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helper): add bottleneck helper; (#56)
- Loading branch information
1 parent
47a3ac7
commit 9463140
Showing
7 changed files
with
244 additions
and
15 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
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,37 @@ | ||
import assert from 'assert'; | ||
import {bottleneck, AxiosPromise} from "../../lib/index.js"; | ||
import sinon from "sinon"; | ||
import {promisify} from 'util'; | ||
|
||
describe('bottleneck', () => { | ||
it('should support for concurrency', () => { | ||
let pending = 0; | ||
const concurrency = 2; | ||
|
||
const fn = bottleneck(function* () { | ||
assert.ok(pending++ < concurrency, `pending tasks count exceeds concurrency`); | ||
yield AxiosPromise.delay(100); | ||
pending--; | ||
}, {concurrency}); | ||
|
||
return Promise.all([ | ||
fn(), | ||
fn(), | ||
fn(), | ||
fn(), | ||
]) | ||
}); | ||
|
||
it('should support for cancellation of preempted tasks', () => { | ||
const fn = bottleneck(function* () { | ||
yield AxiosPromise.delay(500); | ||
}, {cancelRunning: true, concurrency: 2}); | ||
|
||
return Promise.all([ | ||
assert.rejects(fn, /CanceledError/), | ||
assert.rejects(fn, /CanceledError/), | ||
fn(), | ||
fn(), | ||
]) | ||
}) | ||
}); |