If a user accidentally passes a non-Promise-returning function (or a function that throws a synchronous exception) to .use, .use will throw an exception and never release its resource.
One way this came up for me was using .use to access some property on the resource that is a cached value of some recent external state (e.g. statistics from a database server).
For example:
async function getFreeMemory(): Promise<number> {
const memory = await myPool.use(resource => resource.memory);
return memory.free;
}
Calling the above function will throw TypeError: fn(...).then is not a function and the resource will never be released. This happens here.
If a user accidentally passes a non-Promise-returning function (or a function that throws a synchronous exception) to
.use,.usewill throw an exception and never release its resource.One way this came up for me was using
.useto access some property on the resource that is a cached value of some recent external state (e.g. statistics from a database server).For example:
Calling the above function will throw
TypeError: fn(...).then is not a functionand the resource will never be released. This happens here.