Use setImmediate instead of setTimeout(fn,0)