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

Allow asynchronous commands #6

Open
haykam821 opened this issue Feb 11, 2022 · 4 comments
Open

Allow asynchronous commands #6

haykam821 opened this issue Feb 11, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@haykam821
Copy link
Contributor

Currently, the return type of CommandDispatcher#execute is a number, as the Command type requires a number | void return type. As a result, commands cannot be executed asynchronously.

@misode
Copy link
Owner

misode commented Apr 25, 2022

Does Mojang/brigadier allow commands to be executed asynchronously?

@haykam821
Copy link
Contributor Author

Asynchronous commands aren't supported in the Java library, but Java does not have promise or async/await support like JavaScript does. Promises would have a less intrusive presence on Brigadier than Java's futures.

@misode
Copy link
Owner

misode commented Apr 26, 2022

I'm unsure whether this would be possible, I still want to support synchronous command execution as there are cases where async execution is unpreferable.

When CommandDispatcher#execute runs it should know in advance whether or not it will return a promise or not. One idea I had was a generic parameter for the dispatcher, arguments and commands that extends number | Promise<number>. I may try this later but not sure it's going to work.

Kind of similar to Mojang/brigadier#62 I realize, maybe I can take this as inspiration

@misode misode added the enhancement New feature or request label Sep 8, 2023
@haykam821
Copy link
Contributor Author

Although such an approach wouldn't be entirely backwards compatible, I think the Command type could include promises, and the CommandDispatcher#execute method could upgrade the return type to a promise if any individual command returned a promise. As long as the command tree does not contain any commands returning promises, the CommandDispatcher#execute method will never return a promise.

Alternatively, your approach could work, but would require a fair bit of refactoring to pass the type parameter down from the command source to nodes.

I hope asynchronous commands become possible in the future no matter what approach is taken, because promises unlock to ability to do particularly neat things that aren't easily possible synchronously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants