refactor(timer): centralize microtask types and queueMicrotask access; expand nextTick and microtask coverage#576
Conversation
nev21
commented
May 29, 2026
- move MicrotaskFn and ScheduleMicrotaskFn from microtask.ts to types.ts
- move getQueueMicrotask and hasQueueMicrotask from microtask.ts to environment.ts
- update exports in index.ts to expose moved APIs from their new modules
- update internal imports across timer microtask modules and nextTick to use shared helper types/environment access
- update scheduleNextTick in nextTick.ts to prefer process.nextTick, then queueMicrotask, then existing fallback resolution
- add internal queue scheduler helper in microtaskQueue.ts
- extend tests in microtask.test.ts for internal microtask queue rescheduling behavior
- extend tests in nextTick.test.ts for Promise fallback ordering and no-Promise/no-microtask edge scenarios
- align nextTick tests to explicitly disable queueMicrotask where Promise/timer fallback behavior is being validated
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #576 +/- ##
==========================================
- Coverage 99.35% 99.17% -0.18%
==========================================
Files 165 179 +14
Lines 5089 5475 +386
Branches 1116 1200 +84
==========================================
+ Hits 5056 5430 +374
- Misses 33 45 +12
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Centralizes microtask-related types and the queueMicrotask accessor into shared helper modules, threads them through the timer subsystem, updates scheduleNextTick to prefer queueMicrotask after process.nextTick, adds a new internal queue-batched microtask scheduler, and extends test coverage for fallback ordering and queue semantics.
Changes:
- Move
MicrotaskFn/ScheduleMicrotaskFntohelpers/types.tsandgetQueueMicrotask/hasQueueMicrotasktohelpers/environment.ts; re-point internal imports and root exports accordingly. - Update
scheduleNextTickto fall back throughqueueMicrotaskbetweenprocess.nextTickand the Promise/timer paths, plus add a new_getMicrotaskQueueFnbatching helper inmicrotaskQueue.ts. - Expand microtask/nextTick tests to cover queueMicrotask batching across queue types and Promise/timer-fallback ordering scenarios.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/src/helpers/types.ts | Adds MicrotaskFn and ScheduleMicrotaskFn type aliases. |
| lib/src/helpers/environment.ts | Adds getQueueMicrotask / hasQueueMicrotask exports. |
| lib/src/index.ts | Re-exports the moved types and environment helpers from their new modules. |
| lib/src/timer/microtask.ts | Removes the moved types/accessors and imports them from new locations. |
| lib/src/timer/nextTick.ts | Adds queueMicrotask to the fallback chain and updates TSDoc. |
| lib/src/timer/microtasks/microtaskQueue.ts | New helper batching queueMicrotask calls per queue type. |
| lib/src/timer/microtasks/{cancellableTask,processNextTick,promiseQueue,resolveScheduleFn,runMicrotask}.ts | Repoint type imports to helpers/types. |
| lib/test/src/common/timer/microtask.test.ts | Adds coverage for _getMicrotaskQueueFn rescheduling and queue-type ordering. |
| lib/test/src/common/timer/nextTick.test.ts | Disables queueMicrotask in fallback paths and adds Promise/timer-fallback ordering tests. |
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
…; expand nextTick and microtask coverage - move MicrotaskFn and ScheduleMicrotaskFn from microtask.ts to types.ts - move getQueueMicrotask and hasQueueMicrotask from microtask.ts to environment.ts - update exports in index.ts to expose moved APIs from their new modules - update internal imports across timer microtask modules and nextTick to use shared helper types/environment access - update scheduleNextTick in nextTick.ts to prefer process.nextTick, then queueMicrotask, then existing fallback resolution - add internal queue scheduler helper in microtaskQueue.ts - extend tests in microtask.test.ts for internal microtask queue rescheduling behavior - extend tests in nextTick.test.ts for Promise fallback ordering and no-Promise/no-microtask edge scenarios - align nextTick tests to explicitly disable queueMicrotask where Promise/timer fallback behavior is being validated
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot