BackgroundJob class
Work done off the user interface, on a thread of its own where the platform has threads.
The work reports how far it is through the JobProgress it gets, and stops when it's asked to. It must not touch anything the user interface uses meanwhile, only what it was given. Once IsDone() returns true, the results can be taken after Wait(), which returns at once then. A job that goes away before its work ended asks it to stop and waits for it. A job runs its work once, it can't be moved, the thread refers to it.
Constructors, destructors, conversion operators
- BackgroundJob()
- ~BackgroundJob()
- BackgroundJob(const BackgroundJob&) deleted
Public functions
- auto operator=(const BackgroundJob&) -> BackgroundJob& deleted
- auto Start(Function<void(JobProgress&)>&& work, const char* threadName) -> bool
- Starts the work on a thread of its own named
threadName. - void RunHere(Function<void(JobProgress&)>&& work)
- Does the work right away, on the calling thread.
- auto IsDone() const -> bool
- Returns
trueonce the work ended, done or stopped. - void Wait()
- Waits for the work to end, the thread is joined then.
- auto GetProgress() -> JobProgress&
- Returns how far the work is.
- void Cancel()
- Asks the work to stop, see JobProgress::
IsCancelled().
Function documentation
bool Jazz2:: Editor:: BackgroundJob:: Start(Function<void(JobProgress&)>&& work,
const char* threadName)
Starts the work on a thread of its own named threadName.
Without threads, or if the thread can't be started, the work is done right away. Returns true if it runs on the thread.