- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 7
 
RFC 0014: Cancelable timers #14
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but I think a use case will help in visualizing it further. Do you mind adding it?
| 
           @beta-ziliani Ah, I pushed a new draft between your review. I removed the implementation details to focus on the API, and added a technical example to the reference section for the mutex from the guide section.  | 
    
… improve guide section
| 
           And with a last polish pass to finish the DRAFT.  | 
    
| 
           @straight-shoota I renamed the RFC to "cancelable timers", clarified the summary/motivation sections, and reorganized the sections. Is it better? I made the rationale a distinct section, and put it between the guide and reference sections, so we flow from motivation -> explanation with example -> how to implement the timeout -> proposed API -> code example for the explanation (based on how + api).  | 
    
| 
           I included your suggestions 👍  | 
    
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
| 
           This pull request has been mentioned on Crystal Forum. There might be relevant details there: https://forum.crystal-lang.org/t/ambiguous-use-of-time-span-span/8324/1  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments and questions.
Another question: Would this affect the channel's timeout? Do you expect them to share any implementation? Will this have any implicancy if we ever make select to be channel agnostic?
| 
           @beta-ziliani I indeed plan to try and use it to implement the   | 
    
| 
           Returning to this with a fresh 🧠 and following @beta-ziliani's remarks, I think we could have: 
 I'm leaving aside the absolute timers because they're relative to a specific clock and we shall solve that first.  | 
    
| 
           Both the RFC and the implementation PR have been updated to reflect the above proposal.  | 
    
| 
           This pull request has been mentioned on Crystal Forum. There might be relevant details there: https://forum.crystal-lang.org/t/rfc-14-cancelable-timers/8386/1  | 
    
| 
           every time I think of timers for loops I always go back to this blog post. https://vorpus.org/blog/timeouts-and-cancellation-for-humans/. I think we should abstract timeout and other reasons to cancel into a cancellation token - there are other reasons to abort async code besides timeouts  | 
    
| 
           This pull request has been mentioned on Crystal Forum. There might be relevant details there: https://forum.crystal-lang.org/t/ambiguous-use-of-time-span-for-duration-and-monotonic-clock/8324/14  | 
    
| 
           I love the idea of doing the user API for cancellation with a go-style   | 
    
| 
           Perhaps a bit more succinctly: this RFC is about providing an abstraction which provides clarity for who exactly owns the capability to resume a fiber. This is applicable to all ways of stopping a fiber operation, regardless of the user-facing API. Maybe getting a concensus on using a user-facing cancellation token would enable a better internal API, but this should be quite easy to refactor later regardless.  | 
    
| 
           @RX14 Trying to use the mechanism in the sync shard, I realized that   | 
    
Synchronization primitives, such as mutexes, condition variables, pools, or event channels, could take advantage of a general timeout mechanism.
Crystal has a mechanism in the event loop to suspend the execution of a fiber for a set amount of time (
#sleep). It also has a couple mechanisms to add timeouts: one associated to IO operations, and another tailored toChannelandselectto support the timeout branch of select actions.Adding timeouts to all the synchronization primitives in the stdlib, and possibly to custom ones in shards and applications, shouldn't be much harder than calling
#sleep, or need to hack into the privateFiber#timeout_event.Preview: https://github.com/crystal-lang/rfcs/blob/general-timeouts/text/0014-cancelable-timers.md