promiseHooks.onSettled(settled)
settled
<Function> 当 promise 被解决或拒绝时调用的settled
回调。- 返回: <Function> 调用以停止钩子。
settled
钩子必须是普通函数。 提供异步函数会抛出异常,因为它会产生无限微任务循环。
import { promiseHooks } from 'node:v8';
const stop = promiseHooks.onSettled((promise) => {});
const { promiseHooks } = require('node:v8');
const stop = promiseHooks.onSettled((promise) => {});
settled
<Function> Thesettled
callback to call when a promise is resolved or rejected.- Returns: <Function> Call to stop the hook.
The settled
hook must be a plain function. Providing an async function will
throw as it would produce an infinite microtask loop.
import { promiseHooks } from 'node:v8';
const stop = promiseHooks.onSettled((promise) => {});
const { promiseHooks } = require('node:v8');
const stop = promiseHooks.onSettled((promise) => {});