Timer

From Ark & Atlas Server API
Jump to: navigation, search

Go Back: Plugin_Development

Timed Function

/**
 * Executes function after X seconds
 * callback - Callback function
 * delay - Delay in seconds
 * args - Callback arguments
 */
template <typename Func, typename... Args>
void DelayExecute(const Func& callback, int delay, Args&&... args)

Example callback:

void TimerCallBack(int arg1, int arg2)
{
	Log::GetLog()->info("CallBack Executed Args: {}, {}", arg1, arg2);
}

Calling a function with arguments "1234, 100" after 10 seconds.

API::Timer::Get().DelayExecute(&TimerCallBack, 10, 1234, 100);

Recurring Function

/**
 * Executes function every X seconds
 * callback - Callback function
 * execution_interval - Delay between executions in seconds
 * execution_counter - Amount of times to execute function, -1 for unlimited
 * async - If true, function will be executed in the new thread
 * args - Callback arguments
 */
template <typename Func, typename... Args>
void RecurringExecute(const Func& callback, int execution_interval, int execution_counter, bool async, Args&&... args)

Example callback:

void TimerCallBack(int arg1, int arg2)
{
	Log::GetLog()->info("CallBack Executed Args: {}, {}", arg1, arg2);
}

Calling a recurring function with arguments "1234, 100" every 5 seconds.

API::Timer::Get().RecurringExecute(&TimerCallBack, 5, -1, false, 1234, 100);

Calling a recurring function with arguments "1234, 100" 3 times with delay 5 seconds between executions.

API::Timer::Get().RecurringExecute(&TimerCallBack, 5, 3, false, 1234, 100);

Go Back: Plugin_Development