Skip to content

Conversation

@jianyi-gronk
Copy link
Contributor

In the current implementation of MultiHook, there is no check for whether a method exists on each hook before invoking it, I think this maybe lead to issues.

For example:

const hook = new MultiHook([new SyncHook(), new AsyncSeriesHook()]);

hook.tap("A", () => {
  console.log("A");
});  // This works on both hooks

hook.tapPromise("B", () => {
  console.log("B");
});  // This will throw because SyncHook does not have tapPromise

I think a better approach would be to skip the call on any hook that does not support the method, rather than throwing an error.

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.97%. Comparing base (f54ebea) to head (8b21f33).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #199   +/-   ##
=======================================
  Coverage   97.97%   97.97%           
=======================================
  Files          13       13           
  Lines         692      692           
  Branches      113      118    +5     
=======================================
  Hits          678      678           
  Misses         13       13           
  Partials        1        1           
Flag Coverage Δ
integration 97.97% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait
Copy link
Member

MultiHook was not design to use with SyncHook and AsyncHook, these check will lead to loss performance, better just document it

@jianyi-gronk
Copy link
Contributor Author

Got it, thanks for the explanation. Just to confirm: MultiHook was not design to use with SyncHook and AsyncHook, so, it's not expected to support adding the same interceptor to both a SyncHook and an AsyncHook at the same time via MultiHook, right?

@alexander-akait
Copy link
Member

Yes, it was design only to use the same class, i.e. you can use MultiHook with only SyncHook or MultiHook with only AsyncHook, you can't mix SyncHook and AsyncHook for MultiHook, but I am open to improve it like you done here, but I want to see the real usage, we didn't initially intend for this use to be used, so there are no checks for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants