-
Notifications
You must be signed in to change notification settings - Fork 611
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
Refactor TimedRobot, add support for one-shot actions and cancelling … #7315
Open
emintz
wants to merge
3
commits into
wpilibsuite:main
Choose a base branch
from
emintz:Refactor-Timed-Robot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+621
−40
Commits on Oct 30, 2024
-
Refactor TimedRobot, add support for one-shot actions and cancelling …
…actions, along with support for actions that cancel themselves. Changes include: Implement TimedRobot.Cancellable, a functional interface invoked to cancel a scheduled callback. Implement an enum represention of the schedule status where each enumeration contains a callback handler. Implement TimedRobot.Callback.invoke() to handle Runnable invocation on behalf of the TimedRobot, where the method returns true if and only if the callback should be invoked again. Have invoke() delegate callback invocation to the callback's status. Replace Callback.func.run() invocations with Callback.invoke(), and reschedule the callback if and only if invoke() returns true. Enhance TimedRobot.Callback to maintain its schedule status and enhance the addPeriodic() methods to set the scheduling status to PERIODIC (i.e. indefinite periodic invocation) and to return a Cancellable (the Callback that holds the user-provided Runnable) so that applications can cancel invocation at will. Base the enhanced class on Cancellable and implement cancel(). The returned Cancellable is actually the Callable that holds the user's Runnable. Add TimedRobot.addOneShot(), which schedules a Runnable to be invoked exactly once after a set delay. Like its addPeriodic() counterparts, addOneShot() returns a Cancellable. The enhanced TimedRobot currently provides one addOneShot version that takes a timeout in seconds. Please let me know if users will need to specify delays as a Time. Simplify the loop in TimedRobot.startCompetition() and enhance it to reschedule a callback when and only when its callback() invocation returns true. Note that the status enumerations, PERIODIC, ONE_SHOT, and CANCELLED each provide an invoke() method that accepts a Runnable and "does the right thing." The enumerations have the following characteristics | Name | Action | Runs Callback | Returns | +-----------+---------------------- +---------------+---------+ | PERIODIC | Invoke indefinitately | Yes | true | +-----------+---------------------- +---------------+---------+ | ONE_SHOT | Invoke exactly once | Yes | false | +-----------+---------------------- +---------------+---------+ | CANCELLED | Cancel invocation | No | false | +-----------+---------------------- +---------------+---------+ For example, ONE_SHOT.invoke(Runnable callback) invokes callback.run(), but returns false so it will not be rescheduled. The other implications work similarly.
Configuration menu - View commit details
-
Copy full SHA for 318dc1f - Browse repository at this point
Copy the full SHA 318dc1fView commit details
Commits on Oct 31, 2024
-
Refactor TimedRobot, add support for one-shot actions and cancelling …
…actions, along with support for actions that cancel themselves. Changes include: Implement TimedRobot.Cancellable, a functional interface invoked to cancel a scheduled callback. Implement an enum represention of the schedule status where each enumeration contains a callback handler. Implement TimedRobot.Callback.invoke() to handle Runnable invocation on behalf of the TimedRobot, where the method returns true if and only if the callback should be invoked again. Have invoke() delegate callback invocation to the callback's status. Replace Callback.func.run() invocations with Callback.invoke(), and reschedule the callback if and only if invoke() returns true. Enhance TimedRobot.Callback to maintain its schedule status and enhance the addPeriodic() methods to set the scheduling status to PERIODIC (i.e. indefinite periodic invocation) and to return a Cancellable (the Callback that holds the user-provided Runnable) so that applications can cancel invocation at will. Base the enhanced class on Cancellable and implement cancel(). The returned Cancellable is actually the Callable that holds the user's Runnable. Add TimedRobot.addOneShot(), which schedules a Runnable to be invoked exactly once after a set delay. Like its addPeriodic() counterparts, addOneShot() returns a Cancellable. The enhanced TimedRobot currently provides one addOneShot version that takes a timeout in seconds. Please let me know if users will need to specify delays as a Time. Simplify the loop in TimedRobot.startCompetition() and enhance it to reschedule a callback when and only when its callback() invocation returns true. Note that the status enumerations, PERIODIC, ONE_SHOT, and CANCELLED each provide an invoke() method that accepts a Runnable and "does the right thing." The enumerations have the following characteristics | Name | Action | Runs Callback | Returns | +-----------+---------------------- +---------------+---------+ | PERIODIC | Invoke indefinitately | Yes | true | +-----------+---------------------- +---------------+---------+ | ONE_SHOT | Invoke exactly once | Yes | false | +-----------+---------------------- +---------------+---------+ | CANCELLED | Cancel invocation | No | false | +-----------+---------------------- +---------------+---------+ For example, ONE_SHOT.invoke(Runnable callback) invokes callback.run(), but returns false so it will not be rescheduled. The other implications work similarly. Also fix lint errors.
Configuration menu - View commit details
-
Copy full SHA for 3c8db23 - Browse repository at this point
Copy the full SHA 3c8db23View commit details -
Configuration menu - View commit details
-
Copy full SHA for a4207d8 - Browse repository at this point
Copy the full SHA a4207d8View commit details
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.