auto_route_library icon indicating copy to clipboard operation
auto_route_library copied to clipboard

Question about guards - order of execution is sequential or parallel?

Open dJani97 opened this issue 2 years ago • 2 comments

Are guards executed sequentially, one after another, in the order of definition? Or are they executed in parallel with each other?

If I define two guards on a route, like so: guards: [AuthStatusPrefetcher, AuthGuard], can the second guard rely on the data fetched by the first guard, if the first guard only calls resolver.next() once the required data is fetched?

dJani97 avatar Aug 24 '22 19:08 dJani97

It seems to me that the guards are executed sequentially, in order of definition.

I would like to know if that's intentional, and if I can confidently build on top of this behavior, for example by using the above pattern.

dJani97 avatar Aug 24 '22 19:08 dJani97

Yes, you can do that, but not directly passing data between guards, instead you need to cache the result somewhere from the first route guard and then retrieve it to the next. And yes, guards are executed sequentially in order of definition, a series of completers waiting to be completed by resolver.next(). So if your first guard prefetching yields error, you can call resolver.next(false) so it will not execute the next guard, and redirect somewhere else.

grinder15 avatar Aug 29 '22 13:08 grinder15

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

github-actions[bot] avatar Dec 12 '22 08:12 github-actions[bot]