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

v4: Automatically emit Gateway commands for State wrappers #400

Open
diamondburned opened this issue Aug 3, 2023 · 0 comments
Open

v4: Automatically emit Gateway commands for State wrappers #400

diamondburned opened this issue Aug 3, 2023 · 0 comments
Milestone

Comments

@diamondburned
Copy link
Owner

diamondburned commented Aug 3, 2023

Background

Currently, state.X methods will check the cabinet for any gateway-received data, and if none is seen, it'll fall back to checking the API and storing the API response into the cabinet.

A major issue with this approach is cache stateless: the stored item is effectively never renewed because Discord never knew to send updates over the (stateless) gateway. Ideally, the state function should let Discord know of this.

Idea

State methods should send a command over to the gateway whenever it can to notify that the returned item should be kept updated. For example, State.Member could do the following:

member = cabinet.Member()
if member:
	return member

reply = session.Send(RequestGuildMembersCommand)
member = await (session.WaitFor(reply) or api.Member())
return member

Specifically for RequestGuildMembersCommand, some debouncing will be required: within duration d (e.g. 250ms), collect all interested member IDs for a guild, assign it a nonce, then try to wait for either a reply for that nonce or for the given context to expire. The state cache will automatically pick up unhandled events and load them into the state cache.

@diamondburned diamondburned added this to the v4 milestone Aug 3, 2023
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

No branches or pull requests

1 participant