API reference › @evolu/common › Schedule › collectWhileScheduleOutput
function collectWhileScheduleOutput<Output>(
predicate: Predicate<Output>,
): <Input>(
schedule: Schedule<Output, Input>,
) => Schedule<readonly Output[], Input>;
Defined in: packages/common/src/Schedule.ts:1722
Collects outputs while a predicate is true.
More flexible than collectAllScheduleOutputs — stops collecting when the predicate returns false.
Collecting while output matches
import {
assertErr,
assertOk,
collectWhileScheduleOutput,
done,
exponential,
testCreateDeps,
type Millis,
} from "@evolu/common";
// Collect delays only while they remain below one second.
const smallDelays = collectWhileScheduleOutput((delay: Millis) => delay < 1000)(
exponential("100ms"),
);
const step = smallDelays(testCreateDeps());
step(undefined);
step(undefined);
step(undefined);
assertOk(step(undefined), [[100, 200, 400, 800], 800]);
assertErr(step(undefined), done());