feathers-hooks-common icon indicating copy to clipboard operation
feathers-hooks-common copied to clipboard

[feature idea]: sequential every and some hooks

Open ghsamm opened this issue 5 years ago • 0 comments
trafficstars

Hello guys,

I'm submitting the basic idea here and once you approve it, I'll add the PR with types and tests et al.

The current every and some hooks run the input hooks in parallel, but the problem with that approach is that we can't take advantage of short-circuiting.

For example, if we want to make sure the user is:

  1. is authenticated
  2. AND has access to the resource

Using the existing every hook, both checks will run for every request.

But if we had a everySeq hook for example, if the user is not authenticated, we can run the first check only and directly return an error.

Of course, for a small example like this, it wouldn't make much difference. But sometimes, one of the checks could be resource-intensive and we'd would want to live it till the end to avoid running for most requests.

What do you think ?

ghsamm avatar Feb 03 '20 16:02 ghsamm