Skip to content

Commit

Permalink
fix: Updated shared promises file, so that it doesn't require a callb…
Browse files Browse the repository at this point in the history
…ack function (but works with it if supplied)

Signed-off-by: mrickard <maurice@mauricerickard.com>
  • Loading branch information
mrickard committed Jul 8, 2024
1 parent f643c72 commit 754f2ab
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions test/benchmark/promises/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ const tests = [
promises.push(prom.then(function first() {}))
promises.push(prom.then(function second() {}))
}
Promise.all(promises).then(cb)
Promise.all(promises).then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -37,7 +42,12 @@ const tests = [
for (let i = 0; i < NUM_PROMISES; ++i) {
prom = prom.then(function () {})
}
prom.then(cb)
prom.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -47,7 +57,12 @@ const tests = [
for (let i = 0; i < NUM_PROMISES / 2; ++i) {
prom = prom.then(function () {}).catch(function () {})
}
prom.then(cb)
prom.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -57,7 +72,14 @@ const tests = [
for (let i = 0; i < NUM_PROMISES - 1; ++i) {
prom = prom.then(function () {})
}
prom.catch(function () {}).then(cb)
prom
.catch(function () {})
.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -69,7 +91,10 @@ const tests = [
res()
})
}
cb()
if (typeof cb === 'function') {
return cb()
}
return cb || true
}
},

Expand All @@ -87,7 +112,12 @@ const tests = [
})
)
}
Promise.all(promises).then(cb)
Promise.all(promises).then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -101,7 +131,12 @@ const tests = [
})
})
}
prom.then(cb)
prom.then(() => {
if (typeof cb === 'function') {
return cb()
}
return cb || true
})
}
},

Expand All @@ -110,7 +145,10 @@ const tests = [
new Promise(function () {
throw new Error('Whoops!')
}).catch(() => {})
cb()
if (typeof cb === 'function') {
return cb()
}
return cb || true
}
}
]
Expand Down

0 comments on commit 754f2ab

Please sign in to comment.