Skip to content

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 ParameterDescription
EThe event type
ParameterTypeDescription
handlerAbortableEventHandler<E>An AbortableEventHandler that can signal abort

Funcware<Func<E, any>>

Funcware that wraps an event handler, aborting if signaled

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 abortable event handler that aborts if event.cancel is true
const abortIfCancelled = (ev, abort) => { if (ev.cancel) abort(); };
const handler = (ev) => console.log('Handled:', ev);
const abortableHandler = abortable(abortIfCancelled)(handler);
abortableHandler({ cancel: true }); // Does not log
abortableHandler({ cancel: false }); // Logs 'Handled: ...'