Kill task via future
Open, NormalPublic

Description

It should be possible to kill tasks via the future to ensure no further continuation is called.
This is useful for jobs that are started and access an object in the continuation, which will result in undefined behaviour if the object is gone by the time we get to the continuation.

API wise we could have:

  • Future::kill that is called by the referenced object destructor
  • Future::getHandle() that is a smart pointer so the job is automatically killed as soon as the handle dies.
  • Future::addHandle(QObject/smart pointer) so the job is automatically killed as soon as the referenced object dies.

Or just do .exec(guard);
The guard object could be any qobject/smart pointer/...

The guard facility should probably be added on the job level, otherwise subjobs can't use the facility to protect themselves.
Guards could work similarly to the context. Call .guard(QObject*/smart pointer) and be sure that no continuation will be called if the guard is gone.

cmollekopf triaged this task as Normal priority.Apr 6 2017, 6:14 PM