const attempts = []
for (let i = 0; i < workers.length; i++) {
data.seed = bigintToHex((bigintRandom() & ~((1n << 24n) - 1n)), 16)
- attempts.push(new Promise((found, err) => {
+ const attempt = new Promise((resolve, reject) => {
const w = workers[i]
- w.onerror = err
+ w.onerror = reject
w.onmessage = (msg) => {
const result = msg.data
LOG: logger.log(`received result from worker ${i}`)
- found(result)
+ resolve(result)
}
LOG: logger.log(`sending data to worker ${i}`)
w.postMessage(JSON.stringify(data))
- }))
+ })
+ attempts.push(attempt)
}
Promise.all(attempts).then(results => {
const result = results.find(r => typeof r === 'bigint')