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

feat(crux_time): cancellable timer #279

Merged

Conversation

PatrykBuniX
Copy link
Contributor

@PatrykBuniX PatrykBuniX commented Oct 21, 2024

Hi! I was playing around with the time capability and realised there's no way to clear the pending timer. This PR adds this possibility.

This PR adds TimeId field for relevant requests/responses of crux_time capability. Since we know the id of the timer we are able to clear it using the new time request: TimeRequest::Clear {id: TimeId}. Once core notifies the shell (notify_shell since we don't expect any response to this particular request) with this effect, the shell should fire the initially set timer sooner with a TimeResponse::Cleared instead of TimeResponse::InstantArrived/TimeResponse::DurationElapsed.

I'm open to any suggestions, I'm also aware that this is a breaking change, maybe you guys see a non-breaking solution to this? Otherwise I will just create a custom capability 😉

@PatrykBuniX PatrykBuniX force-pushed the feat/crux_time/cancellable-timer branch from c43b7bd to 86d1ecf Compare October 21, 2024 12:14
@PatrykBuniX PatrykBuniX marked this pull request as ready for review October 21, 2024 12:15
Copy link
Member

@charypar charypar left a comment

Choose a reason for hiding this comment

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

Looks great, we've had something like that in mind as well, just didn't get around to it. Thank you!

Can I ask what the use for this was that you found?

@PatrykBuniX
Copy link
Contributor Author

Can I ask what the use for this was that you found?

I was persisting the timer fire date and resuming it upon app reload and of course I didn't want the timer to live forever, hence the need to clear it.

@charypar
Copy link
Member

charypar commented Oct 21, 2024

Makes a lot of sense!

We've got an issue in the backlog to think about how we do effect cancellation universally for all effects (#247), but this is good for timer 👍🏻

@PatrykBuniX
Copy link
Contributor Author

@charypar I don't think the ci failure is related with the changes I made, can you take a look or re-run? 🙏

@charypar
Copy link
Member

charypar commented Oct 21, 2024

Yea, that looks like a must_use has been added on Update, which the examples have not been updated for. /cc @StuartHarris

@StuartHarris
Copy link
Member

StuartHarris commented Oct 21, 2024

@PatrykBuniX my apologies. I really should have published crux_core as 0.10.0 instead of 0.9.1, although it should be only tests that are affected.

I'll merge it anyway! Thanks for your help with this!

@StuartHarris StuartHarris merged commit 0b2d1f2 into redbadger:master Oct 21, 2024
6 of 9 checks passed
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.

3 participants