GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
AsyncTask Class Reference

Public Member Functions

 isGarbage ()
 
 setGarbage ()
 
 isFinished ()
 
 run ()
 
 isCrashed ()
 
 getResult ()
 
 cancelRun ()
 
 hasCancelledRun ()
 
 hasResult ()
 
 setResult ($result, $serialize=true)
 
 setTaskId ($taskId)
 
 getTaskId ()
 
 getFromThreadStore ($identifier)
 
 saveToThreadStore ($identifier, $value)
 
 onRun ()
 
 onCompletion (Server $server)
 
 cleanObject ()
 
- Public Member Functions inherited from Threaded
 chunk ($size, bool $preserve=false)
 
 count ()
 
 isRunning ()
 
 isTerminated ()
 
 merge ($from, $overwrite=true)
 
 notify ()
 
 notifyOne ()
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 pop ()
 
 run ()
 
 shift ()
 
 synchronized (\Closure $function, $args=null)
 
 wait ($timeout)
 
 getRefCount ()
 
 addRef ()
 
 delRef ()
 
 isGarbage ()
 

Data Fields

 $worker = null
 

Additional Inherited Members

- Static Public Member Functions inherited from Threaded
static extend ($obj)
 

Detailed Description

Class used to run async tasks in other threads.

An AsyncTask does not have its own thread. It is queued into an AsyncPool and executed if there is an async worker with no AsyncTask running. Therefore, an AsyncTask SHOULD NOT execute for more than a few seconds. For tasks that run for a long time or infinitely, start another pocketmine\Threadinstead.WARNING:DonotcallPocketMine-MPAPImethods,orsaveobjects(andarrayscontainingobjects)from/onotherThreads!!

Member Function Documentation

◆ cancelRun()

cancelRun ( )
101  {
102  $this->cancelRun = true;
103  }

◆ cleanObject()

cleanObject ( )
188  {
189  foreach($this as $p => $v){
190  if(!($v instanceof \Threaded) and !in_array($p, ["isFinished", "isGarbage", "cancelRun"])){
191  $this->{$p} = null;
192  }
193  }
194  }

◆ getFromThreadStore()

getFromThreadStore (   $identifier)

Gets something into the local thread store. You have to initialize this in some way from the task on run

Parameters
string$identifier
Returns
mixed
150  {
151  global $store;
152  return $this->isGarbage() ? null : $store[$identifier];
153  }

◆ getResult()

getResult ( )
Returns
mixed
97  {
98  return $this->serialized ? unserialize($this->result) : $this->result;
99  }

◆ getTaskId()

getTaskId ( )
Returns
int
138  {
139  return $this->taskId;
140  }

◆ hasCancelledRun()

hasCancelledRun ( )
Returns
bool
108  {
109  return $this->cancelRun === true;
110  }

◆ hasResult()

hasResult ( )
Returns
bool
115  {
116  return $this->result !== null;
117  }

◆ isCrashed()

isCrashed ( )
Returns
bool
90  {
91  return $this->crashed;
92  }

◆ isFinished()

isFinished ( )
Returns
bool
66  : bool{
67  return $this->isFinished;
68  }

◆ isGarbage()

isGarbage ( )
Returns
bool

Implements Collectable.

55  : bool{
56  return $this->isGarbage;
57  }

◆ onCompletion()

onCompletion ( Server  $server)

Actions to execute when completed (on main thread) Implement this if you want to handle the data in your AsyncTask after it has been processed

Parameters
Server$server
Returns
void
184  {
185 
186  }

◆ onRun()

onRun ( )
abstract

Actions to execute when run

Returns
void

◆ run()

run ( )
70  {
71  $this->result = null;
72  $this->isGarbage = false;
73 
74  if($this->cancelRun !== true){
75  try{
76  $this->onRun();
77  }catch(\Throwable $e){
78  $this->crashed = true;
79  $this->worker->handleException($e);
80  }
81  }
82 
83  $this->isFinished = true;
84  //$this->setGarbage();
85  }

◆ saveToThreadStore()

saveToThreadStore (   $identifier,
  $value 
)

Saves something into the local thread store. This might get deleted at any moment.

Parameters
string$identifier
mixed$value
162  {
163  global $store;
164  if(!$this->isGarbage()){
165  $store[$identifier] = $value;
166  }
167  }

◆ setGarbage()

setGarbage ( )
59  {
60  $this->isGarbage = true;
61  }

◆ setResult()

setResult (   $result,
  $serialize = true 
)
Parameters
mixed$result
bool$serialize
123  {
124  $this->result = $serialize ? serialize($result) : $result;
125  $this->serialized = $serialize;
126  }

◆ setTaskId()

setTaskId (   $taskId)
Parameters
$taskId
131  {
132  $this->taskId = $taskId;
133  }

Field Documentation

◆ $worker

$worker = null

The documentation for this class was generated from the following file: