/**
 * Defers a destroy callback so that portal-driven DOM moves
 * (disconnect + reconnect in the same microtask) can cancel the
 * destroy before it fires.
 */
export class DeferredDestroy {
    constructor() {
        this.pendingDestroyTimer = null;
    }
    /**
     * Schedule a deferred destroy callback. Any previously pending
     * callback is cancelled first.
     * @param callback
     */
    schedule(callback) {
        this.cancel();
        this.pendingDestroyTimer = setTimeout(() => {
            this.pendingDestroyTimer = null;
            callback();
        }, 0);
    }
    /**
     * Cancel the pending destroy callback, if any.
     */
    cancel() {
        if (this.pendingDestroyTimer !== null) {
            clearTimeout(this.pendingDestroyTimer);
            this.pendingDestroyTimer = null;
        }
    }
}
