export interface ConnectAutomationBatch { controller: AbortController; stopCurrentRun: (() => Promise) | null; } export const createConnectAutomationBatch = (): ConnectAutomationBatch => ({ controller: new AbortController(), stopCurrentRun: null, }); export const trackConnectAutomationStop = ( batch: ConnectAutomationBatch, stopCurrentRun: (() => Promise) | null, ): void => { batch.stopCurrentRun = stopCurrentRun; }; export const cancelConnectAutomationBatch = async ( batch: ConnectAutomationBatch, ): Promise => { batch.controller.abort(); if (batch.stopCurrentRun) { await batch.stopCurrentRun(); } };