The correct way to implement 'cancelling the parent from a child'. Instead of passing in the cancel func from parent to child, the parent listens on a specific cancellation channel. The parent passes the channel to the child. Each time the child attempts to send an output to the output channel, it does so with a newly create time-out context. If that time-out occurs, then the child sends a cancellation notification on the cancel channel. The parent on seeing this cancelation request will invoke cancel on the context, resulting in the entire worker-pool shutting down.
The correct way to implement 'cancelling the parent from a child'. Instead of passing in the cancel func from parent to child, the parent listens on a specific cancellation channel. The parent passes the channel to the child. Each time the child attempts to send an output to the output channel, it does so with a newly create time-out context. If that time-out occurs, then the child sends a cancellation notification on the cancel channel. The parent on seeing this cancelation request will invoke cancel on the context, resulting in the entire worker-pool shutting down.
See: