Async & Promises
Implement Abortable Async Task
mediumJS SpecificJS / TS3 tests
Problem Statement
Implement `makeAbortable(taskFn)` that wraps an asynchronous function to support cancellation via standard `AbortSignal`. The returned function has signature `(signal, ...args) => Promise<any>`. Requirements: 1. If `signal` is already aborted when called, immediately reject with `signal.reason || new Error('Aborted')` without starting `taskFn`. 2. If `signal` fires `'abort'` while `taskFn` is executing, immediately reject with the abort reason without waiting for `taskFn` to settle. 3. If `taskFn` settles before abort, resolve or reject with `taskFn`'s outcome. 4. Clean up event listeners so no memory leaks occur after completion.
Examples
Example:
const run = makeAbortable(async (id) => fetchData(id));
const controller = new AbortController();
const promise = run(controller.signal, 42);
controller.abort(new Error('Cancelled by user'));
// promise rejects immediately with 'Cancelled by user'JavaScript & TypeScript starter code included
Run this as a live interviewPractice solo
3 test cases. No second person needed.