Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch compose #2795

Merged
merged 2 commits into from
Feb 23, 2024
Merged

Dispatch compose #2795

merged 2 commits into from
Feb 23, 2024

Conversation

ronag
Copy link
Member

@ronag ronag commented Feb 21, 2024

This relates to...

Rationale

Changes

Features

Bug Fixes

Breaking Changes and Deprecations

Status

@ronag
Copy link
Member Author

ronag commented Feb 22, 2024

@mcollina @metcoder95 PTAL

@ronag ronag force-pushed the dispatch-compose branch 10 times, most recently from 40d7cdb to d1fb5b2 Compare February 22, 2024 07:41
Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much like the concept, it will be interesting as it allows chaining and executing the dispatching one after the other, sequentially.

Just left few comments, I'll give a second look and possibly start doing a review more of the actually implementation within Redirect and Retry handler.

Do you have an idea already for the TS types?

lib/interceptors/redirect.js Outdated Show resolved Hide resolved
lib/dispatcher.js Show resolved Hide resolved
lib/dispatcher.js Show resolved Hide resolved
@ronag ronag force-pushed the dispatch-compose branch 16 times, most recently from 8e2a6f4 to 9a1a398 Compare February 22, 2024 17:37
@ronag ronag force-pushed the dispatch-compose branch 6 times, most recently from 0f22b71 to 5c1f6c2 Compare February 22, 2024 19:12
@metcoder95
Copy link
Member

@mcollina Unfortunately this API conflicts with the mock API. I found a hack around it but not sure... wdyt? I believe we could probably re-writen the mock API to use the same intercept API but that's beyond me.

Although I agree it overlaps, I'm not 100% we sure change it, they share similar concepts but have different purposes. The mock simplifies the testing quite a lot, especially for simple scenarios; using the dispatcher.intercept might be cumbersome for that (but not essential bad).

@ronag
Copy link
Member Author

ronag commented Feb 23, 2024

As I see it we have 3 options.

  1. Hacky compat where we check the arguments to decide which intercept the user intends.
  2. Rename dispatcher.intercept (maybe compose?)
  3. Rename mock.intercept

@ronag
Copy link
Member Author

ronag commented Feb 23, 2024

Some ideas:

dispatcher = dispatcher.intercept(redirect(redirectOpts), retry(retryOpts))
dispatcher = dispatcher.compose(redirect(redirectOpts), retry(retryOpts))
dispatcher = compose(redirect(redirectOpts), retry(retryOpts))(dispatcher)
dispatcher = intercept(redirect(redirectOpts), retry(retryOpts))(dispatcher)

dispatcher.dispatch(dispatchOpts)

@mcollina
Copy link
Member

I would rename dispatcher.composer

@metcoder95
Copy link
Member

+1 on dispatcher.compose

@ronag
Copy link
Member Author

ronag commented Feb 23, 2024

@mcollina @metcoder95 wdyt? Are we happy with this API? I'm going to leave documenting it as a TODO for merging next into main. I suspect we might iterate on this even further.

@ronag
Copy link
Member Author

ronag commented Feb 23, 2024

I really like how e.g. ProxyAgent nicely folds into this pattern.

const proxyAgent = new Agent().compose(proxyOpts)

@mcollina
Copy link
Member

Can we have it on main instead? It would ease very well the transition.

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Happy to port this to main

@ronag ronag merged commit 649185a into next Feb 23, 2024
11 of 17 checks passed
@ronag
Copy link
Member Author

ronag commented Feb 23, 2024

Happy to port this to main

Can you open a separate PR for that and maybe add some documentation as well as update the existing interceptor documentation as deprecated?

@mcollina
Copy link
Member

Having next and main having two different implementation of the same thing is a recepie for disaster in maintenance and release. I recommend this is reverted in next, implemented in next and ported to next.

I would need to merge main into next one day, and this will make things very hard.

@ronag
Copy link
Member Author

ronag commented Feb 23, 2024

. I recommend this is reverted in next, implemented in next and ported to next.

Sorry that's confusing?

Wouldn't cherry-picking this into main be the same thing?

@mcollina
Copy link
Member

mcollina commented Feb 23, 2024

This is based on some other changes in the next branch and I think the end result would be a mess when we try to merge main into next, with main already having those changes landed by a different PR.

ronag added a commit that referenced this pull request Feb 23, 2024
@ronag
Copy link
Member Author

ronag commented Feb 23, 2024

Reverted. @metcoder95 have fun with that 😄

@ronag ronag mentioned this pull request Feb 25, 2024
13 tasks
@Uzlopak Uzlopak deleted the dispatch-compose branch February 26, 2024 01:32
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 24, 2024
* feat: new interceptors API

* WIP: compose
KhafraDev pushed a commit to KhafraDev/undici that referenced this pull request Jun 24, 2024
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.

None yet

3 participants