Loading homepage
Extend promisify(fn) with a custom override so callback-based APIs can choose their own return value or adapt a non-standard callback signature.
Attach the override using fn[promisify.custom] = customFunction. Your implementation must prefer this function and otherwise use the error-first, callback-last behavior from Promisify.
Input: const add = (a, b, callback) => callback(null, a + b); await promisify(add)(2, 3); Output: 5
Input: const task = (callback) => callback(null, "original"); const custom = () => Promise.resolve("custom"); task[promisify.custom] = custom; promisify(task) === custom; await promisify(task)(); Output: true "custom"
Input: const task = () => {}; task[promisify.custom] = () => 42; promisify(task)(); Output: 42 (returned directly, without an extra Promise)
The custom override is returned unchanged. Only the fallback adapts callbacks to promises.