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
Request: offer Job creation that will allow us to have the option on it : cancel, and cancel-with-interruption #2509
Comments
Thanks for the request. We've considered such API (#1934), but decided to give up on it: thread interruption is not-so-widespread and mostly used wrongly. Also, such a design, unfortunately, is too intrusive and requires special |
@qwwdfsad But Kotlin is supposed to work with Java code fine, and on Java it's the way to stop long running operations. |
For usages of blocking code, it is recommended to use |
@qwwdfsad Not sure I understand. You mean to say that it is possible to choose how to cancel a given code, with interruption and without, after the task was created? |
|
@qwwdfsad I don't understand. How when using this, you will then be able to choose to cancel it with interruption and without? |
Got it, thanks for the clarification. Could you please elaborate on the use-case of such an API? Maybe the use-case will shed some light on other potential solutions that are less intrusive and can be introduced to the JVM-only module |
@qwwdfsad Yes, sure. I wrote the use case before, so I will explain again: |
Could you please explain the actual domain-specific problem? E.g. why it is important to be able to dynamically choose cancellation mode and why the problem couldn't be solved otherwise (e.g. via Becuase when AsynkTask was deprecated, there wasn't any demand or actual use-cases of such a flexibility |
@qwwdfsad This reminds me of a very similar case. I was told that the perfect replacement for IntentService (which was deprecated) is WorkManager. I tried what I can to migrate to it, but then I noticed a very weird thing: all app-widgets got updated more often than usual. I was sure I did something wrong and spent hours on finding out what's going on. Was sure that I didn't implement WorkManager or that I ruined something with App-widget. And Google, instead of admitting this is a terrible implementation that didn't occur before and didn't need a special care, closed the issue with saying that you should use a ridiculous workaround instead: Always have a pending work for WorkManager. So, this should show you a good lesson of how it's best to offer migrations. Migrations should have the minimal issues possible. Should avoid workarounds. Should cover as much as possible from the original (otherwise why switch?). Google works today a lot on Compose. How would you think people would react if in the end it won't have a very basic thing they were used to (like TextView) , and Google will just say to use some workaround instead (like "it's ok, draw your own text") ? That's how basic it is here. Canceling a task the way you want. That's very basic. |
Currently, either you use
runInterruptible
or you don't.If you use it,
cancel
will interrupt.If you don't,
cancel
will not interrupt.The creation of the instance forces
cancel
to work in one way or the other. You have no choice after it's created.On AsyncTask (here), you have a choice for every instance.
cancel(true)
will interrupt, andcancel(false)
will not .The creation of the instance doesn't force you to choose how it will be canceled.
You can choose to cancel with interruption in some case, and without in another.
The text was updated successfully, but these errors were encountered: