[solved] Let other code runs when no more fiber

I am in the process of migrating code to Meteor 3.0

We use to use a sleep function in big loop :

for (let i = 0; i <= 9999; i++) {
   if (row % 100 === 0) sleep(200);

The sleep function is defined like this :

const Fiber = require('fibers');
const sleep = function (ms) {
    const fiber = Fiber.current;
    setTimeout(function () {
    }, ms);

The purpose of this code was to stop the loop for 200 ms every 100 iterations to let eventually other methods to run.

As we won’t have fiber anymore, I suppose this won’t work anymore but I don’t know how to have the same behavior without fiber.

Do you guys have any idea ? Thanks

Some forum links

You’ll want this to be an async function

const sleep = async function (ms) {
   return new Promise(resolve => setTimeout(resolve, ms));

await sleep(500);
1 Like

Note, that async sleep will not work in array.forEach, you either need for..of or for (let i = ...)

1 Like

Thanks to both of you. I have migrated my fiber-sleep to a non-fiber-sleep.
Have a nice weekend.