Skip to content

Draft / Suggestion: Bot shared state available via context - #57

Draft
ivan-jukic wants to merge 1 commit into
mainfrom
suggestion/bot-shared-state
Draft

Draft / Suggestion: Bot shared state available via context#57
ivan-jukic wants to merge 1 commit into
mainfrom
suggestion/bot-shared-state

Conversation

@ivan-jukic

Copy link
Copy Markdown
Contributor

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. 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)

---
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.
jwt: &str,
public_key: &str,
now: TimestampMillis,
shared_state: S,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?


impl<R> CommandHandlerRegistry<R> {
pub fn new(oc_client_factory: Arc<ClientFactory<R>>) -> CommandHandlerRegistry<R> {
impl<R, S> CommandHandlerRegistry<R, S> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants