-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add support for a post-processing hook at the request level #92
Comments
Hey Nigel! I just want to add some clarification that I properly understand the goal and scope of this ticket. The main goal here is to add in an optional request method that allows people to consistently do some sort of basic action (like updating the user in a general manager) every single time the request is run, but before the result is returned from the request as a whole. In a whole, it will essentially act as the very final step, receiving the result of the request, doing an action, and then returning the result of the request, ending the functionality the request as a whole. Is that correct? |
That is correct. |
I've spend some time exploring ticket #92 and implementing this works perfectly without having access to |
Given the natures of the above conversation, I've decided to push the code I wrote up to a draft PR to help the conversation. |
I think the concern is definitely founded, it looks to me like there is a (likely resolvable, but annoying) mismatch here. That bug does predate the switch to async/await so at that point Result was used in a lot of places that are I think using Result if we do that does still make sense, you say "we can either have the post process take in a successful finalResource or an error", but "final resource or an error" IS pretty much the definition of the Doing it with Result seems still possible, but I think requires similar processing in both the success and failure cases. i.e. probably in
Which will WORK, but is pretty gross, and has some weird edge cases (post process gets called twice if post process changes a success into an error, for example). I can't think of a better way to handle that though. |
Right now, if you want to do any common operation on the final result of a Netable request (say storing something to a global cache), you need to either implement your own finalize function and do it there (which works in some cases but can seem bit strange, and also doesn't have access to the error which might be usefull in some cases), or you need to write a function wrapping the Netable call in some way (which can lead to the sort of excessive abstraction and wrapping describe in #78).
As an an alternative, we could provide another per-request customization point along side decode and finalize that runs after finalize and has an opportunity to use the contents of the incoming request:
A client that wanted to take a global action on a specific type of request, could then implement that to get access to the result without needing a wrapper function:
The text was updated successfully, but these errors were encountered: