Repository navigation
0.18 PR5: support async stopWhen predicates - #28
Merged
Merged
Conversation
stopWhen checked the predicate without awaiting it, so an async predicate returned a Promise — always truthy — and stopped the iteration on the first item. Await the result before deciding to yield. stopWhenSync now rejects a thenable predicate result via assertSyncCallback, producing a TypeError that names stopWhen() as the async alternative instead of silently treating a Promise as truthy. Docs updated for the new contract in reference and guide.
ildella
marked this pull request as ready for review
November 24, 2026 14:28
ildella
commented
Nov 24, 2026
ildella
left a comment
Owner
Author
There was a problem hiding this comment.
APPROVED
REVIEW: Both review passes found no medium-or-higher issues. stopWhen now awaits its predicate — a Promise<false> keeps the item, a truthy result stops before the item is yielded — and stopWhenSync rejects thenables through the existing assertSyncCallback helper with a TypeError naming stopWhen(). A rejecting async predicate surfaces as a source error (not onError), consistent with how sync predicate throws already behave. Guide and reference docs cover both functions.
FINDINGS: No medium-or-higher findings. Low/info follow-ups:
- LOW —
await predicate(...)defers each sync predicate's result by one microtask. Trigger: any timing-sensitive consumer of a fully syncstopWhensource; no library consumer or existing test observes it, and the predicate call itself stays synchronous after the pull. - LOW — four new tests repeat the same
async () => { await Promise.resolve(); ... }fixture. Trigger: changing how a "genuinely async" predicate is built requires four edits; test-only duplication, not duplicated production derivation. - INFO —
tests/stop-when-sync.test.jsasserts the exact error string. Trigger: rephrasing the shared message insrc/shared.jsbreaks the test despite unchanged behavior; this matches established repo convention. - INFO — the guide says "when it returns a Promise", while
awaitalso unwraps arbitrary thenables. Trigger: a thenable predicate; code handles it, wording is narrower. Cosmetic. - INFO — out of scope and pre-existing: under
strategy: 'throw', a predicate that throwsundefinedrethrowsundefinedverbatim.
CI: green — the test check (Code Check workflow) succeeded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / why
stopWhencalled the predicate without awaiting it. An async predicate returned a Promise — always truthy — so iteration stopped on the first item, silently.stopWhennow awaitspredicate(item, index)before deciding to yield, soasync () => falsekeeps every item andasync () => truestops correctly.A rejecting async predicate keeps the existing source-error behaviour: it surfaces through
onSourceError/sourceErrors, neveronError.stopWhenSyncnow rejects a thenable predicate result through the existingassertSyncCallbackhelper. The error is aTypeErrornaming the async alternative:stopWhenstays a truthiness stop predicate:dropis not special there (that is PR 6).Tests
tests/stop-when.test.js: asyncfalse→ all items; asynctrue→ stop; await happens before yield (index still(item, index)); rejecting async predicate consumed byseries→ source error.tests/stop-when-sync.test.js: async / Promise-returning predicate →TypeErrornamingstopWhen().Verification
yarn lint— clean, 0 warningsyarn vitest run— 71 files, 938 tests passedyarn check— duplicate/clone and knip cleanDocs
docs/reference.md#stopwhen(sync or async),#stopwhensync(sync only, thenable rejected), and the guide's source-adapters section.Plan:
.opencode/plan/pipelean-0.18.md, PR 5.