Draft / Suggestion: Bot shared state available via context - #57
Draft
ivan-jukic wants to merge 1 commit into
Draft
Draft / Suggestion: Bot shared state available via context#57ivan-jukic wants to merge 1 commit into
ivan-jukic wants to merge 1 commit into
Conversation
--- Allows bots to hold shared state on the bot context. Commands would be able to access this state within their `execute` handlers as `ctx.shared_state`. This would provide SDK support for shared state, though making the type signatures somewhat more complex.
hpeebles
reviewed
Feb 27, 2025
| jwt: &str, | ||
| public_key: &str, | ||
| now: TimestampMillis, | ||
| shared_state: S, |
Contributor
There was a problem hiding this comment.
If we have to pass in the shared state every time that would look messy for the majority of use cases where the shared state will be ().
So maybe we instead hold the shared state in the CommandHandlerRegistry?
Then it automatically passes it through to command_handler.execute.
Or are you envisioning potentially passing in different instances, but the type always remains the same?
hpeebles
reviewed
Feb 27, 2025
|
|
||
| impl<R> CommandHandlerRegistry<R> { | ||
| pub fn new(oc_client_factory: Arc<ClientFactory<R>>) -> CommandHandlerRegistry<R> { | ||
| impl<R, S> CommandHandlerRegistry<R, S> { |
Contributor
There was a problem hiding this comment.
If we were to hold the state on the CommandHandlerRegistry then we could set a default for S as S = (), and then expose a with_shared_state which would hand the value to CommandHandlerRegistry and also set the S generic type on the returned instance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows bots to hold shared state on the bot context.
Commands would be able to access this state within their
executehandlers asctx.shared_state. Command definition structs would only need to reference local state.This would provide SDK support for shared state, though making the type signatures somewhat more complex. For not shared state we'd use unit type
().(breaking change)