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

Experimental - Cancel-able Menus #69

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

kantenkugel
Copy link
Member

@kantenkugel kantenkugel commented Aug 10, 2018

Pull Request

Pull Request Checklist

Please follow the following steps before opening this PR.

PRs that do not complete the checklist will be subject to denial for
missing information.

Pull Request Information

Check and fill in the blanks for all that apply:

  • My PR fixes a bug, error, or other issue with the library's codebase.
  • My PR is for the menu and commons modules of the JDA-Utilities library.
  • My PR creates a new module for the JDA-Utilities library: ______.

Description

This module adds the possibility to cancel EventWaiter tasks via the new return value of EventWaiter#waitForEvent (Future<Void>)

This new feature is used to add Menu#cancel() to cancel menus that are already running.

Todo:

  • Discuss if this is the proper way of doing this or if some mechanics should be changed
  • Javadocs
  • Decide how to handle cancelFuture.cancel(true) vs false
  • Should there be a cancel method that doesn't execute the cancel/final action? What about the EventWaiter cancellation?
  • Eventually throw errors on display() if already being displayed somewhere, as this would currently prevent proper functionality of Menu#cancel()
  • Wait for PR [Feature] MessagePaginator: Paginator-alike Menu but for raw Messages #58 to be merged and patch it as well in this PR
  • Extensive testing
  • Final review

@kantenkugel kantenkugel added Enhancement Modification of existing code-base to enhance quality and/or functionality. Module: Commons Related to the "commons" module. Proposal Proposal for a new feature, enhancement, or changes. Module: Menu Related to the "menu" module. labels Aug 10, 2018
@Shengaero Shengaero self-assigned this Aug 15, 2018
@Shengaero Shengaero self-requested a review August 15, 2018 16:33
@kantenkugel
Copy link
Member Author

Should probably also wait for #58 to be merged so i can apply the changes from this PR to that code as well. Adding it to the TODO

@kantenkugel kantenkugel changed the title Experimental cancelablemenus Experimental - Cancel-able Menus Aug 15, 2018
Copy link
Collaborator

@Shengaero Shengaero left a comment

Choose a reason for hiding this comment

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

Here are some initial things I have questions about that we can start with.

I am rather hesitant about this proposal, I will need to see how it evolves as we progress through the todo list.

My main concerns as of right now are compatibility, this PR introduces some pretty big breaking changes as it is. I am not opposed to breaking things, but we should try to avoid any if possible.

private Future<Void> cancelFuture;
private Message attachedMessage;

protected Menu(EventWaiter waiter, Set<User> users, Set<Role> roles, long timeout, TimeUnit unit, Consumer<Message> finalAction)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately, this breaks compatibility with previous versions for people who implemented their own menus.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add an overloaded Constructor without finalAction that just calls this one with null finalAction (for old menus, not using the new methods)

* @param cancelFuture
* The cancel Future returned from {@code EventWaiter#waitForEvent}
*/
protected final void setCancelFuture(Future<Void> cancelFuture)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am concerned about the implied functionality through these two methods.

What if my menu doesn't need cancellation functionality? Should I still use them? Is it safe for my menu to not have cancel functionality?

This needs to be documented, and if it is required I'd appreciate it mentioned in the class level documentation for Menu.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a big block in the class-level docs of Menu describing the whole system and its use

public void cancel()
{
if(cancelFuture == null)
throw new IllegalStateException("Menu was not yet displayed or is already cancelled");
Copy link
Collaborator

Choose a reason for hiding this comment

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

So if I don't set the cancelFuture, then the menu wasn't displayed or was already cancelled...?

I think more appropriately this should be "Menu didn't have cancelFuture set to cancel" or something to that effect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably better to change the message to something like "Menu can not be cancelled (not supported, not yet displayed or already ended)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Modification of existing code-base to enhance quality and/or functionality. Module: Commons Related to the "commons" module. Module: Menu Related to the "menu" module. Proposal Proposal for a new feature, enhancement, or changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants