AsyncTask
in package
Creates an asynchronous task and adds it to the queue.
Asynchronous tasks in xRefCore are tick-based and run on the same thread as the rest of the application. This implementation of asynchronous tasks is designed to execute some lightweight code at a specified interval.
Note! If your asynchronous task doesn't work correctly, or it works in not whole application, try to add "declare(ticks = 1);" right after "<?php"
Table of Contents
- __construct() : mixed
- Cancel() : void
- Cancel task. If you cancel task, it won't be executable anymore and will be removed from scheduler
- Execute() : void
- Execute task manually.
- GetExecutedTimes() : int
- GetNextExecution() : float
- GetParameters() : IAsyncTaskParameters
- GetTaskId() : int
- GetThis() : object
- IsCancelled() : bool
- IsFinished() : bool
- Returns TRUE if it is one-off task and was executed, or it's reusable task and was cancelled. Otherwise, returns FALSE.
- IsOnce() : bool
- SetNextExecution() : void
- Sets a new next task's time execution
- SetThis() : void
- Sets new "this"
- WasExecuted() : bool
Methods
__construct()
public
__construct(object $MyThis, int $Interval, bool $RunOnce, callable $TaskCallback[, IAsyncTaskParameters|null $Parameters = null ]) : mixed
Parameters
- $MyThis : object
-
Object context where task will be executed
- $Interval : int
-
Execution interval in milliseconds
- $RunOnce : bool
-
Execute task once
- $TaskCallback : callable
-
Callback-function which will be executed in $MyThis context. Callback should accept two parameters: AsyncTask (your task) and IAsyncTaskParameters (your parameters)
- $Parameters : IAsyncTaskParameters|null = null
-
Additional arguments
Tags
Return values
mixed —Cancel()
Cancel task. If you cancel task, it won't be executable anymore and will be removed from scheduler
public
Cancel() : void
Return values
void —Execute()
Execute task manually.
public
Execute() : void
Return values
void —GetExecutedTimes()
public
GetExecutedTimes() : int
Return values
int —How many times task was executed
GetNextExecution()
public
GetNextExecution() : float
Return values
float —Next task's execution time in Unixtime format in milliseconds
GetParameters()
public
GetParameters() : IAsyncTaskParameters
Return values
IAsyncTaskParameters —Additional arguments
GetTaskId()
public
GetTaskId() : int
Return values
int —Task ID
GetThis()
public
GetThis() : object
Return values
object —Object's context for its execution
IsCancelled()
public
IsCancelled() : bool
Return values
bool —Returns true if task was cancelled
IsFinished()
Returns TRUE if it is one-off task and was executed, or it's reusable task and was cancelled. Otherwise, returns FALSE.
public
IsFinished() : bool
Return values
bool —IsOnce()
public
IsOnce() : bool
Return values
bool —Will task be executed once
SetNextExecution()
Sets a new next task's time execution
public
SetNextExecution(float $Time) : void
Parameters
- $Time : float
-
New execution time in Unixtime format in milliseconds. If you don't set time, then the next execution time will be "now + interval"
Tags
Return values
void —SetThis()
Sets new "this"
public
SetThis(object $myThis) : void
Parameters
- $myThis : object
Return values
void —WasExecuted()
public
WasExecuted() : bool
Return values
bool —Was task executed at least once