Wanzyee Studio
PeriodicInquirer< T >

For a value source without change event, periodically check it to invoke an event when changed. More...

Public Member Functions

 PeriodicInquirer ()
 Create an inquirer for setup each behavior and start manually. More...
 
 PeriodicInquirer (Func< T > inquirer, Action< T, T > onUpdated, float interval=0f, bool start=true)
 Create an inquirer with common settings, optional to start immediately. More...
 
void Stop ()
 Stop running periodic checking. More...
 
void Start ()
 Start running periodic checking. More...
 

Public Attributes

float interval
 The interval seconds to check the value. More...
 
Func< T > inquirer
 The callback to get the current value. More...
 
Func< bool > stopper
 The callback to check if to stop, default not to stop automatically. More...
 
bool running => null != _coroutiner && !_coroutiner.isDone
 Determine if currently running. More...
 

Properties

current [get]
 Get the current value. More...
 

Events

Action< T, T > onUpdated = (old, now) => {}
 The event invoked when the value updated. More...
 

Detailed Description

For a value source without change event, periodically check it to invoke an event when changed.

Template Parameters
TThe value type.

Constructor & Destructor Documentation

Create an inquirer for setup each behavior and start manually.

PeriodicInquirer ( Func< T >  inquirer,
Action< T, T >  onUpdated,
float  interval = 0f,
bool  start = true 
)

Create an inquirer with common settings, optional to start immediately.

Parameters
inquirerThe callback to get the current value.
onUpdatedThe event invoked when the value updated.
intervalThe interval seconds to check the value.
startIf to start immediately.

Member Function Documentation

void Stop ( )

Stop running periodic checking.

void Start ( )

Start running periodic checking.

Member Data Documentation

float interval

The interval seconds to check the value.

Func<T> inquirer

The callback to get the current value.

Func<bool> stopper

The callback to check if to stop, default not to stop automatically.

bool running => null != _coroutiner && !_coroutiner.isDone

Determine if currently running.

Property Documentation

T current
get

Get the current value.

Event Documentation

Action<T, T> onUpdated = (old, now) => {}

The event invoked when the value updated.

First invoked when Start(), both parameters are the current value. Then every time the value changed, invoked with the last and the current value.