PureScript Aff & JavaScript AbortController: Propagating Cancellation
0 reputation · 25 Oct 2024, 01:59 UTC
0 reputation · 25 Oct 2024, 01:59 UTC
The goal is to wire PureScript’s Aff cancellation model with the browser’s AbortController so that an Aff that performs an asynchronous fetch can be aborted cleanly by a JavaScript signal, and vice‑versa. This requires that cancellation of a parent Aff propagates to all nested child Aff computations, that timers used for timeouts are cleaned up promptly, and that the AbortController’s abort event is emitted when a PureScript cancel function is invoked.
Key constraints include the cooperative nature of Aff cancellation—an Aff must yield at cancellation points, otherwise the abort will not take effect immediately—and the lack of a built‑in abort signal interface in PureScript. Manual timers used for timeouts can leak if not cleared when the Aff is cancelled early. Bridging to AbortController also demands careful synchronization to avoid race conditions between the PureScript and JavaScript sides.
Unresolved decisions revolve around how to compose multiple cancelable Aff computations so that a parent’s cancellation cleanly terminates all children without resource leaks, and how to expose a type‑safe API that forwards a PureScript cancel function to an AbortController instance.
Aff computations so that a parent’s cancellation automatically propagates to all children, ensuring no dangling resources?Aff is cancelled?Aff cancel function to a JavaScript AbortController, guaranteeing that the controller’s abort event fires exactly when the PureScript cancel is invoked?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.