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

defer: add a map_deferred_response in rhai #1219

Closed
Tracked by #80
Geal opened this issue Jun 10, 2022 · 4 comments · Fixed by #1501
Closed
Tracked by #80

defer: add a map_deferred_response in rhai #1219

Geal opened this issue Jun 10, 2022 · 4 comments · Fixed by #1501

Comments

@Geal
Copy link
Contributor

Geal commented Jun 10, 2022

rhai runs synchronously, so it cannot apply to all of the deferred responses at once. The current plan emerging from #1206 is to apply the current map_response behaviour on the headers and the first response (which should be directly available in most cases), then support another rhai callback that can be applied on deferred responses.
In this way we keep the current behaviour for normal queries

@garypen
Copy link
Contributor

garypen commented Jun 13, 2022

I don't understand why rhai would need this function, but other plugins wouldn't. Is it to allow for async cancellation?

The bit I'm struggling with is this: we'd never know (when we write a plugin) whether we should expect a query to have deferred elements or not, so preserving the current behaviour doesn't seem to yield much benefit. A plugin auther (rhai or otherwise) is always going to need to handle potentially deferred queries.

@Geal
Copy link
Contributor Author

Geal commented Jun 13, 2022

rhai needs it because it is incapable of managing async code, and it won't have the same capabilities between the first response and the deferred ones: on the first response headers are still editable, while in deferred responses they will not.
My first idea was actually to separate the headers and response mapping, but doing it instead with headers+first response and then adding a callback will not break the current rhai plugins

@garypen
Copy link
Contributor

garypen commented Jun 13, 2022

Presumably the ability to edit response headers in subsequent deferred responses will also not be possible with native Rust plugins. How will we handle that in map_response for native plugins?

@Geal
Copy link
Contributor Author

Geal commented Jun 13, 2022

in native plugins we can edit the headers, then map over the stream, and return a new response with the edited headers and the mapped stream

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants