diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a56d6bf..881ad3d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -255,12 +255,13 @@ export class HTTP extends Service { const timer = config.timeout && setTimeout(() => { controller.abort(new HTTPError('request timeout', 'ETIMEDOUT')) }, config.timeout) - return () => { + return (done?: boolean) => { clearTimeout(timer) + if (done) return controller.abort(new HTTPError('context disposed', 'ETIMEDOUT')) } }) - controller.signal.addEventListener('abort', dispose) + controller.signal.addEventListener('abort', () => dispose()) try { const headers = new Headers(config.headers) @@ -317,7 +318,7 @@ export class HTTP extends Service { } return response } finally { - controller.abort() + dispose(true) } } diff --git a/packages/file/src/index.ts b/packages/file/src/index.ts index 9ec6a49..4a17240 100644 --- a/packages/file/src/index.ts +++ b/packages/file/src/index.ts @@ -23,6 +23,7 @@ export interface FileResponse { } export const name = 'undios-file' +export const inject = ['http'] export interface Config {}