Use setImmediate when available, otherwise fallback to nextTick