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

Cancellation? #5

Closed
AstraLuma opened this issue Jun 29, 2017 · 3 comments
Closed

Cancellation? #5

AstraLuma opened this issue Jun 29, 2017 · 3 comments

Comments

@AstraLuma
Copy link

Sorry this has trickled down to you. Basically, for my use case, I have need to cancel sleeps on certain events so that I can recalculate sleep time.

Related issues are AstraLuma/xontrib-schedule#3 and dbader/schedule#147

  1. Is this a feature you're ok including?
  2. What is the API you'd like to have for this?

I know my work with #4 has a high potential of making this challenging, but the pure-python algorithm should amenable to this, within a second.

@jgillick
Copy link
Owner

I would take that contribution as well! I'm not married to any particular API for this.

Since the existing API is not asynchronous, my first thought would be a callback function passed to the call. This function would be called regularly and return True or False to prematurely cancel the pause or not. This could cause a lot of processor overhead if the callback function is very big.

Another option would be to provide an asynchronous version of this API and add a cancel method.

What were you thinking?

@AstraLuma
Copy link
Author

I'm not sure.

The first thought is fine if you're regularly polling. But I know that's not the case with POSIX timer_create()-based waits. (You just set it to go off on the wall clock and let the kernel handle it. Just sleep through the whole thing with no polling.)

So the underlying implementation has to hand out some kind of cancellation callable. But because of the synchronous nature, we need another way to return it.

I suppose converting it from functional to OOP would work? Make a Sleeper class with all the existing methods, plus a .cancel(). The module-level functions would just make a Sleeper and call the appropriate method.

If you wanted to keep objects and classes out of it, you could add a cancel argument which accepts a callable, which is called with the cancel() function as its argument. (If that explanation made any sense.)

@jgillick
Copy link
Owner

Either way sounds fine to me. I don't have any aversion from classes and OOP.

@jgillick jgillick closed this as completed Nov 2, 2020
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

No branches or pull requests

2 participants