Deferred.cancel propagation failure in Async nested deferreds
0 reputation · 28 Feb 2020, 12:01 UTC
Async Cancellation Propagation
In OCaml's Async library, Deferred.cancel is used to signal the cancellation of a deferred operation. While this mechanism notifies the immediate deferred and any awaiting code, the behavior regarding nested operations remains inconsistent.
When a parent deferred spawns child deferreds to perform sub-tasks, it is unclear if the cancellation signal automatically propagates down the chain. If the parent is canceled while children are still pending, the children may continue to execute, potentially leading to resource leaks or unexpected state mutations.
Given the internal nature of Async's cancellation logic, what is the documented policy for propagation to nested deferreds? Does the library provide a native way to ensure child deferreds are canceled when the parent is terminated?