Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/asyncEachOfLimit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import breakLoop from './breakLoop.js'
import onlyOnce from './onlyOnce.js'

// for async generators
export default function asyncEachOfLimit(generator, limit, iteratee, callback) {
Expand Down Expand Up @@ -26,7 +27,7 @@ export default function asyncEachOfLimit(generator, limit, iteratee, callback) {
return;
}
running++
iteratee(value, idx, iterateeCallback)
iteratee(value, idx, onlyOnce(iterateeCallback))
idx++
replenish()
}).catch(handleError)
Expand Down
15 changes: 15 additions & 0 deletions test/es2017/asyncGenerators.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ module.exports = function () {

this.retries(3);

it('should reject repeated iteratee callbacks for async generators', async () => {
async function * values () {
yield 1
yield 2
}

await async.eachOfLimit(values(), 1, (value, key, callback) => {
callback(null)
callback(null)
}).then(
() => { throw new Error('expected repeated callback to reject') },
err => { expect(err.message).to.equal('Callback was already called.') }
)
})

it('should reject tryEach when the async generator fails before yielding a task', async () => {
const error = new Error('iterator failed')
async function * tasks () {
Expand Down