promiseHooks.onBefore(before)
新增于: v17.1.0, v16.14.0
-
before<Function> 在 promise 继续执行之前调用的before回调。\
before<Function> Thebeforecallback to call before a promise continuation executes. -
返回:<Function> 调用以停止钩子。
\Returns: <Function> Call to stop the hook.
before 钩子必须是普通函数。提供异步函数会抛出异常,因为它会产生无限的微任务循环。
\The before 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.onBefore((promise) => {});const { promiseHooks } = require('node:v8'); const stop = promiseHooks.onBefore((promise) => {});