import type { KibanaRequest } from 'src/core/server' ; export function cancelEsRequestOnAbort < T extends Promise < any > > ( promise , request , controller ) { const subscription = request . events . aborted$ . subscribe ( ( ) => { controller . abort ( ) ; } ) ; return promise . finally ( ( ) => subscription . unsubscribe ( ) ) ; }