Closed
Description
Affected URL(s)
https://nodejs.org/api/util.html#utilabortedsignal-resource
Description of the problem
The docs aren't entirely clear on the purpose of the second optional argument (resource
), how it's supposed to be used, or when it's useful. One of the primary use cases for this util function seems to be aborting a promise that doesn't support abort natively, but I'm not sure what I should pass as the resource?
import { aborted } from 'node:util';
const ac = new AbortController();
const client = new SomeRandomDatabaseClient();
const results = await Promise.race([
client.uncancelableQuery(),
aborted(ac.signal, /* what am i supposed to pass here */),
]);
// somewhere else ac.abort() may or may not ever be called
// but assume ac does go out of scope and get gc'd eventually
Am I thinking about this use case correctly, or is not passing resource somehow creating a memory leak / preventing things from being cleaned up properly?
EDIT: It seems I misunderstood the second argument being optional, it appears required, but questions still remain how it's supposed to be used for the example above.