import{isCancellation as t}from"./utilities.js";export class Cancellable{token;constructor(){this.token=new Promise(((t,n)=>{this.cancel=t=>{n(new Cancellation(t,this.token))}})),this.token.catch((()=>{}))}cancel(t){}}export class Cancellation{reason;token;_gcxIsCancellation=!0;constructor(t,n){this.reason=t,this.token=n}}export async function cancelify(n,e,o){if(void 0===e)return n;try{return await Promise.race([e,n])}catch(n){throw t(n)&&n.token===e&&o&&o(n.reason),n}}export async function cancelifyWithAbortSignal(t,n,e){const o=new AbortController,{signal:c}=o;return cancelify(t(c),n,(t=>{o.abort(),e?.(t)}))}