Skip to content

Bug: setTimeout used instead of microtask queue for promise resolution #503

@MSNev

Description

@MSNev

Description

In lib/src/promise/itemProcessor.ts (lines 44-49), the item processor uses setTimeout for scheduling promise resolution callbacks instead of the microtask queue (queueMicrotask or Promise.resolve().then()).

Impact

  • Promise resolution ordering does not match native Promise behavior
  • Promises resolve in a later macrotask instead of the current microtask checkpoint
  • Code that depends on microtask timing (common in async coordination patterns) may exhibit race conditions
  • Performance penalty from unnecessary event loop round-trips

Steps to Reproduce

javascript console.log('1'); createAsyncPromise(resolve => resolve()).then(() => console.log('3')); console.log('2'); // Native: 1, 2, 3 // With setTimeout: 1, 2, (delay), 3

Suggested Fix

Use queueMicrotask when available, falling back to Promise.resolve().then() or MutationObserver trick, before falling back to setTimeout.

Severity

Medium — timing difference from spec; may cause subtle ordering bugs in applications that depend on microtask semantics.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions