Use process.nextTick instead of setTimeout for loop.