Skip to content

Commit

Permalink
Add scenarioOnEvery util
Browse files Browse the repository at this point in the history
Signed-off-by: Yuriy Yakym <[email protected]>
  • Loading branch information
yuriyyakym committed May 19, 2023
1 parent 5d5deaa commit 603a2d5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export { AwaitableEvent, composeState, delay, scenario, scenarioOnce, rejectAfter } from './lib';
export {
AwaitableEvent,
composeState,
delay,
rejectAfter,
scenario,
scenarioOnce,
scenarioOnEvery,
} from './lib';
export { default as action } from './action';
export { default as state } from './state';
export { default as useFlowValue } from './useFlowValue';
Expand Down
3 changes: 2 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { default as AwaitableEvent } from './AwaitableEvent';
export { default as composeState } from './composeState';
export { default as delay } from './delay';
export { default as noop } from './noop';
export { default as rejectAfter } from './rejectAfter';
export { default as scenario } from './scenario';
export { default as scenarioOnce } from './scenarioOnce';
export { default as rejectAfter } from './rejectAfter';
export { default as scenarioOnEvery } from './scenarioOnEvery';
14 changes: 14 additions & 0 deletions src/lib/scenarioOnEvery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AwaitableEvent from './AwaitableEvent';
import noop from './noop';

const scenarioOnEvery = async <T>(
awaitableEvent: AwaitableEvent<T>,
scenarioFn: (event: T) => Promise<any>,
) => {
while (true) {
const event = await awaitableEvent;
scenarioFn(event).catch(noop);
}
};

export default scenarioOnEvery;

0 comments on commit 603a2d5

Please sign in to comment.