Commit 376a743
authored
fix: eliminate Promise.race handler-stacking in batchPackageStream (#600)
* fix: eliminate Promise.race handler-stacking in batchPackageStream
The prior implementation stored per-generator promises in a Map and
called `Promise.race(running.values())` every loop iteration. Each
race call re-attached fresh `.then` handlers to every still-pending
promise in the pool, so long-surviving generators accumulated
O(iterations) dead handler closures before finally settling.
See nodejs/node#17469 and
https://github.com/cefn/watchable/tree/main/packages/unpromise for
the pattern.
Switch to a single-waiter queue: each generator's `.then` delivers
its step into a buffer, and the main loop awaits a fresh
promiseWithResolvers each iteration. Handlers are one-shot —
nothing to stack.
All 565 tests pass.
* docs(claude): add Promise.race handler-stacking rule
Pairs with the batchPackageStream fix: documents the anti-pattern
so future code does not reintroduce it. Concise bullet in the
SHARED STANDARDS section alongside the existsSync rule.
* docs(claude): drop duplicate Promise.race rule from TypeScript Patterns
The rule already lives in SHARED STANDARDS (line 26). Having it twice
— once general, once under sdk-specific TypeScript Patterns — adds
maintenance drift without adding clarity. Keep the SHARED STANDARDS
version.
* style(sdk): alphabetize destructuring and prefer undefined in batchPackageStream
Align the single-waiter queue with project rules: alphabetical
destructuring/type property order and undefined (not null) for
absent state.1 parent 8fd7ae0 commit 376a743
2 files changed
Lines changed: 51 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
867 | 867 | | |
868 | 868 | | |
869 | 869 | | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
874 | 916 | | |
875 | 917 | | |
876 | 918 | | |
| |||
888 | 930 | | |
889 | 931 | | |
890 | 932 | | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
| 933 | + | |
897 | 934 | | |
898 | 935 | | |
899 | 936 | | |
900 | | - | |
901 | | - | |
| 937 | + | |
| 938 | + | |
902 | 939 | | |
903 | 940 | | |
904 | 941 | | |
| |||
907 | 944 | | |
908 | 945 | | |
909 | 946 | | |
910 | | - | |
911 | | - | |
912 | | - | |
| 947 | + | |
913 | 948 | | |
914 | 949 | | |
915 | 950 | | |
| |||
0 commit comments