UNPKG

@augmentcode/ag-redux-toolkit

Version:

Redux + Saga state management for Svelte apps — designed for AI agents. Includes runtime TypeScript source, AI skills, and reference documentation for robust, observable, high-performance state management.

30 lines (29 loc) • 1 kB
import { createChannelFromSelector } from "../../../utils/sagas/selector-channel-effects.js"; import { call, delay, race, take } from "typed-redux-saga"; //#region src/slices/store-utility/sagas/waitFor.ts var checkValueSaga = function* (channel, isExpectedValue) { while (true) { const { payload: val, prevPayload: prevVal } = yield* take(channel); if (isExpectedValue(val, prevVal)) return true; } }; function* waitFor(selector, args, isExpectedValue, timeoutMs) { if (isExpectedValue(yield* selector.effect(...args), void 0)) return true; const channel = yield* createChannelFromSelector(selector, ...args); const callEffect = call(checkValueSaga, channel, isExpectedValue); try { if (timeoutMs && timeoutMs > 0) { const { value } = yield* race({ value: callEffect, timeout: delay(timeoutMs) }); return value || false; } else yield* callEffect; return true; } finally { channel.close(); } } //#endregion export { waitFor }; //# sourceMappingURL=waitFor.js.map