Skip to content

Commit 1fcff3d

Browse files
committed
Fixed bugs
1 parent a1f3de4 commit 1fcff3d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/findInternal.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ async function findInternal (iterable, iteratee, queueOrConcurrency, ordered) {
3333
let lastIndexHandled = -1
3434
const results = []
3535

36+
let waitListIndex = 0
3637
const waitList = new Map()
37-
const addToWaitList = (identifier, fct) => {
38+
const addToWaitList = (fct) => {
39+
const identifier = waitListIndex
40+
waitListIndex += 1
3841
const p = (async () => {
3942
try {
4043
return [identifier, 'resolved', await fct()]
4144
} catch (e) {
4245
return [identifier, 'rejected', e]
4346
}
4447
})()
45-
assert(!waitList.has('identifier'), 'waitList already contains identifier')
48+
assert(!waitList.has(identifier), 'waitList already contains identifier')
4649
waitList.set(identifier, p)
4750
}
4851
const raceWaitList = async () => {
@@ -63,7 +66,7 @@ async function findInternal (iterable, iteratee, queueOrConcurrency, ordered) {
6366
state: null
6467
}
6568
scheduledList.set(index, task)
66-
addToWaitList(task.index, async () => {
69+
addToWaitList(async () => {
6770
const p = queue.exec(async () => {
6871
if (task.state === 'cancelled') {
6972
throw new CustomCancelledError()
@@ -103,7 +106,7 @@ async function findInternal (iterable, iteratee, queueOrConcurrency, ordered) {
103106
}
104107
const fetch = () => {
105108
fetching = true
106-
addToWaitList('next', async () => {
109+
addToWaitList(async () => {
107110
const [state, result] = await it.next().then((r) => ['resolved', r], (e) => ['rejected', e])
108111
fetching = false
109112
if (state === 'resolved') {

src/mapGenerator.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ async function * mapGenerator (iterable, iteratee, queueOrConcurrency = 1, order
7272
let lastIndexHandled = -1
7373
const results = []
7474

75+
let waitListIndex = 0
7576
const waitList = new Map()
76-
const addToWaitList = (identifier, fct) => {
77+
const addToWaitList = (fct) => {
78+
const identifier = waitListIndex
79+
waitListIndex += 1
7780
const p = (async () => {
7881
const snapshot = await reflectStatus(fct)
7982
return [identifier, snapshot]
8083
})()
81-
assert(!waitList.has(identifier), 'waitList already contains identifier')
84+
assert(!waitList.has(identifier), 'waitList contains identifier')
8285
waitList.set(identifier, p)
8386
}
8487
const raceWaitList = async () => {
@@ -99,7 +102,7 @@ async function * mapGenerator (iterable, iteratee, queueOrConcurrency = 1, order
99102
state: null
100103
}
101104
scheduledList.set(index, task)
102-
addToWaitList(task.index, async () => {
105+
addToWaitList(async () => {
103106
const p = queue.exec(async () => {
104107
if (task.state === 'cancelled') {
105108
throw new CustomCancelledError()
@@ -138,7 +141,7 @@ async function * mapGenerator (iterable, iteratee, queueOrConcurrency = 1, order
138141
}
139142
const fetch = () => {
140143
fetching = true
141-
addToWaitList('next', async () => {
144+
addToWaitList(async () => {
142145
const snapshot = await reflectStatus(() => it.next())
143146
fetching = false
144147
if (snapshot.status === 'fulfilled') {

0 commit comments

Comments
 (0)