-const { TaskFunctions } = require('./test-types')
+const { TaskFunctions } = require('./test-types.js')
const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => {
- return new Promise((resolve) => {
+ return await new Promise(resolve => {
let events = 0
if (numberOfEventsToWait === 0) {
resolve(events)
+ return
}
for (const workerNode of pool.workerNodes) {
workerNode.worker.on(workerEvent, () => {
}
const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => {
- return new Promise((resolve) => {
+ return await new Promise(resolve => {
let events = 0
if (numberOfEventsToWait === 0) {
resolve(events)
+ return
}
pool.emitter?.on(poolEvent, () => {
++events
})
}
-const sleep = async (ms) => {
- return new Promise((resolve) => setTimeout(resolve, ms))
+const sleep = async ms => {
+ return await new Promise(resolve => setTimeout(resolve, ms))
}
const sleepTaskFunction = async (
rejection = false,
rejectionMessage = ''
) => {
- return new Promise((resolve, reject) => {
+ return await new Promise((resolve, reject) => {
setTimeout(
() =>
rejection === true
return Math.floor(Math.random() * (max + 1))
}
-const jsonIntegerSerialization = (n) => {
+const jsonIntegerSerialization = n => {
for (let i = 0; i < n; i++) {
const o = {
a: i
* @param {number} n - The number of fibonacci numbers to generate.
* @returns {number} - The nth fibonacci number.
*/
-const fibonacci = (n) => {
+const fibonacci = n => {
if (n <= 1) return n
return fibonacci(n - 1) + fibonacci(n - 2)
}
* @param {number} n - The number to calculate the factorial of.
* @returns {number} - The factorial of n.
*/
-const factorial = (n) => {
+const factorial = n => {
if (n === 0) {
return 1
}
return factorial(n - 1) * n
}
-const executeTaskFunction = (data) => {
+const executeTaskFunction = data => {
switch (data.function) {
case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.n || 100)