Closed negezor closed 3 months ago
These changes are not functionally equivalent, the prior code intends to delay the resolution by a micro tick
But why? This is not used in other parts of the code 🤔 And only non-equivalent one is toPromise
.
This is because promise timing doesn't actually mix very well with Wonka. This can cause subtle race conditions and bugs. In React Native it even used to cause complete stalls.
The cost here is minimal, in fact, the optimal solution with Wonka is to always avoid converting to or from promises, unless it's absolutely necessary or part of a surfaced API.
The problem with immediately resolving promises is that it becomes very easy to chain logic accidentally into a "single tick" when this isn't desired though. Delaying all promise conversions by a micro tick hence gets rid of a whole class of bugs without causing much of a problem
Summary
Removes unnecessary
Promise
wrappers. SincePromise
can unroll itself, these operations only create overheadFor example:
And
Set of changes
Removing unnecessary
Promise
wrappers insources.ts
andsinks.ts
.