Use setImmediate instead of nextTick