From 107591258a52d445ca002c26a91cba20905037a1 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sun, 1 Jun 2025 23:55:00 +0200 Subject: [PATCH] docs: fix interceptor order description and add visual diagram MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation incorrectly stated that the first interceptor would be called first, but due to function composition, the last interceptor in the array is actually called first. Added ASCII art diagram showing the interceptor stack and request flow to make the execution order clear. Fixes #4241 πŸ€– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Signed-off-by: Matteo Collina --- docs/docs/api/Dispatcher.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/docs/api/Dispatcher.md b/docs/docs/api/Dispatcher.md index e574a6bfb2e..6def7872dbf 100644 --- a/docs/docs/api/Dispatcher.md +++ b/docs/docs/api/Dispatcher.md @@ -841,9 +841,28 @@ try { Compose a new dispatcher from the current dispatcher and the given interceptors. > _Notes_: -> - The order of the interceptors matters. The first interceptor will be the first to be called. +> - The order of the interceptors matters. The last interceptor will be the first to be called. > - It is important to note that the `interceptor` function should return a function that follows the `Dispatcher.dispatch` signature. > - Any fork of the chain of `interceptors` can lead to unexpected results. +> +> **Interceptor Stack Visualization:** +> ``` +> compose([interceptor1, interceptor2, interceptor3]) +> +> Request Flow: +> β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +> β”‚ Request │───▢│interceptor3 │───▢│interceptor2 │───▢│interceptor1 │───▢│ dispatcher β”‚ +> β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ .dispatch β”‚ +> β–² β–² β–² β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +> β”‚ β”‚ β”‚ β–² +> (called first) (called second) (called last) β”‚ +> β”‚ +> β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ +> β”‚ Response │◀───│interceptor3 │◀───│interceptor2 │◀───│interceptor1 β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +> β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ +> +> The interceptors are composed in reverse order due to function composition. +> ``` Arguments: