Can't cancel running @task?

I've got a button triggered function that executes a for loop over a data set list and makes an API call for each. I added the @task decorator to keep it from holding up the UI, and a button triggered function to cancel the task(with a running check first). However, when I trigger the task(and I can see for sure that it's running from console logs), calling the task.cancel() didn't work. I threw in some log entries to check the task state, and they all indicate that the task isn't running(pending/is_current False, not_called True). Any ideas? I'll post the code shortly, I don't get discord on the work computer, so example code is a pain to bring over.
2 Replies
Soulscode
SoulscodeOP9mo ago
Code was to big for the character limit, threw it into a gist. https://gist.github.com/Enochsoul/3ead6207477bc3e3b7add173318099a6
Gist
Solara @task issue example
Solara @task issue example. GitHub Gist: instantly share code, notes, and snippets.
MaartenBreddels
MaartenBreddels9mo ago
Hi @Soulscode when using task with a normal (not async) function, we cannot currently cancel the running code automatically. You task function should call is_current() to see if it should continue running, see https://solara.dev/api/task
Want results from more Discord servers?
Add your server