UpdateJobEvent Class Reference

#include <updatejobevent.h>

Detailed Description

Update Job Event class collects and combine multiple update calls into one call until executed. This is useful when adding multiple update events for the same ui element but if you only want to execute one redraw update. As soon as the update job starts all subsequent request calls will trigger a new update.

UpdateJobEvent _updateEvent;
_updateEvent.Init(
[]()
{
// update call
}, JobQueueRef::GetMainThreadQueue());
_updateEvent.RequestUpdate() iferr_return;
_updateEvent.RequestUpdate() iferr_return;
_updateEvent.RequestUpdate() iferr_return;
_updateEvent.RequestUpdate() iferr_return;
#define iferr_return
Definition: resultbase.h:1519

The update will be called only once if the main thread is blocked or too slow when calling the RequestUpdate functions.

Public Member Functions

 ~UpdateJobEvent ()
 
Result< void > Init (const Delegate< void()> &updateDelegate, const JobQueueRef &jobQueueRef)
 
void Free ()
 
void Init (Delegate< void()> &&updateDelegate, const JobQueueRef &jobQueueRef)
 
Result< void > RequestUpdate (Bool cancelCurrentJob=true)
 

Private Types

using JobWithConfirmedCancellation = ClosureJobWithConfirmedCancellation< Delegate< void()>, JOBCANCELLATION::AUTOMATIC, void >
 

Private Attributes

AtomicBool _updateRequested
 
Delegate< void()> _updateDelegate
 
JobQueueRef _updateJobQueueRef
 
StrongRef< JobWithConfirmedCancellation_lastUpdateJob
 

Member Typedef Documentation

◆ JobWithConfirmedCancellation

using JobWithConfirmedCancellation = ClosureJobWithConfirmedCancellation<Delegate<void()>, JOBCANCELLATION::AUTOMATIC, void>
private

Constructor & Destructor Documentation

◆ ~UpdateJobEvent()

Member Function Documentation

◆ Init() [1/2]

Result<void> Init ( const Delegate< void()> &  updateDelegate,
const JobQueueRef jobQueueRef 
)

Initializes the callback function and queue.

Parameters
[in]updateDelegateCode to execute in update call.
[in]jobQueueRefJob queue to execute the code.
Returns
OK on success.

◆ Free()

void Free ( )

Free Structure.

◆ Init() [2/2]

void Init ( Delegate< void()> &&  updateDelegate,
const JobQueueRef jobQueueRef 
)

Initializes the callback function and queue.

Parameters
[in]updateDelegateCode to execute in update call.
[in]jobQueueRefJob queue to execute the code.

◆ RequestUpdate()

Result<void> RequestUpdate ( Bool  cancelCurrentJob = true)

RequestUpdate enqueues a new update job into the given queue.

Parameters
[in]cancelCurrentJobIf true (the default) and there's a currently running update job, the function cancels the job and waits for that. Make sure that this doesn't introduce dead locks.
Returns
OK on success.

Member Data Documentation

◆ _updateRequested

AtomicBool _updateRequested
private

◆ _updateDelegate

Delegate<void()> _updateDelegate
private

◆ _updateJobQueueRef

JobQueueRef _updateJobQueueRef
private

◆ _lastUpdateJob

StrongRef<JobWithConfirmedCancellation> _lastUpdateJob
private