[async_wrap] enable/disable `PromiseHook` depending on `kTotals`
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines
Affected core subsystem(s)
async_wrap, async_hooks
Description
First revert 410b1417. There's no need to delay setting the callbacks. No native logic exists that checks if these are empty or not. Except the check that occurs just before setting them.
Then use a portion of #13416 to allow removing a PromiseHook from Environment::promise_hooks_
, and add a CHECK()
to Environment::AddPromiseHook()
to make sure the same fn
+ arg
isn't added twice. (@addaleax I kept you as the author)
Finally track the number of enabled hooks via kTotals
and use that to enable/disable AsyncWrap
's PromiseHook
dynamically.