abortable
abortable<
E
>(handler
:AbortableEventHandler
<E
>):Funcware
<Func
<E
,any
>>
Defined in: ext/funcware/abortable.ts:29
Creates funcware that makes an event handler abortable via an AbortableEventHandler.
Use cases:
- Adding abort logic to event handlers or state machine transitions
- Preventing further processing if an abort condition is met
Type Parameters
Section titled “Type Parameters”Type Parameter | Description |
---|---|
E | The event type |
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
handler | AbortableEventHandler <E > | An AbortableEventHandler that can signal abort |
Returns
Section titled “Returns”Funcware
<Func
<E
, any
>>
Funcware that wraps an event handler, aborting if signaled
Source
Section titled “Source”This function is useful for scenarios where you want to conditionally prevent further processing of an event, such as in middleware, guards, or cancellation logic. It integrates abortable event handling into funcware-based systems for composable control flow.
export const abortable = <E>(handler: AbortableEventHandler<E>): Funcware<Func<E, any>> => (inner) => (ev) => { let aborted = false; handler(ev, () => { aborted = true; }); if (!aborted) { return inner(ev); } };
Example
Section titled “Example”// Example abortable event handler that aborts if event.cancel is trueconst abortIfCancelled = (ev, abort) => { if (ev.cancel) abort(); };const handler = (ev) => console.log('Handled:', ev);const abortableHandler = abortable(abortIfCancelled)(handler);abortableHandler({ cancel: true }); // Does not logabortableHandler({ cancel: false }); // Logs 'Handled: ...'