-
Notifications
You must be signed in to change notification settings - Fork 74
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
New base::task features #132
base: beta
Are you sure you want to change the base?
Conversation
Here some points:
|
You are rigth, try catch is needed.
If a task is canceled before entering the work queue, the "done" work would never be called because the execute callback would not be executed. It might make more sense to rename it to "finished" or "completed" instead of "done".
I'm not sure about this either. However I would like to add an on_exception callback, to call it when an exception happens in another callback.
Great, will do it! |
I've added a new function "try_skip" in d32eb3f, this function would be useful to remove work from the queue that wasn't started yet. |
To be sincere I'm not a big fan about making the Probably we can fix some bugs to make the impl even more simple, e.g. about:
We might change the current void task::in_worker_thread()
{
try {
//if (!m_token.canceled()) // removing this line to always call the execution callback
m_execute(m_token);
}
... About the The About all the other features/callbacks (finished, exception, done) I think are not necessary as they could be moved to another wrapper class/abstraction, e.g. the same |
I'm fine with this, I was just trying to keep the current behavior as much as possible by adding optional new behavior.
I'm happy to change it to any other name, so try_pop() is fine by me.
If I remove the friendship, then I got this error: |
Okay, trying the new changes now there is a caveat. This is our new void task::in_worker_thread()
{
m_state = state::RUNNING;
try {
m_execute(m_token);
}
catch (const std::exception& ex) {
LOG(FATAL, "Exception running task: %s\n", ex.what());
}
m_state = state::FINISHED;
} In my [this, func](base::task_token& token) {
try {
func(m_L);
}
catch (const std::exception& ex) {
// TODO: do something
}
m_finished(token);
} Now base::task::m_state is not FINISHED when my m_finished callback gets called. And I was actually removing the task when finished, but now it throws the |
This PR introduces a couple of features to base::task:
This was introduced to be able to do some things in aseprite/aseprite#5037. Like being able to redraw the "Running Scripts" window as needed (when a task is started/done) and to avoid showing the "stop" button for enqueued tasks. Because we can't dequeue tasks (this should be something to add to base::task and base::thread_pool as well I think)
Something to think about: should we use an atomic enum for the base::task state instead of 3 different atomic bools? I believe that a task should be only in one of the following states at any given time: