PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
AsyncTask.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17 
18  *
19  *
20 */
21 
22 namespace pocketmine\scheduler;
23 
25 
31 abstract class AsyncTask extends \Collectable{
32 
33  private $finished = null;
34  private $result = null;
35  private $taskId = null;
36 
37  public function run(){
38  $this->finished = false;
39  $this->result = null;
40 
41  $this->onRun();
42  $this->finished = true;
43  }
44 
48  public function isFinished(){
49  return $this->finished === true;
50  }
51 
55  public function getResult(){
56  return unserialize($this->result);
57  }
58 
62  public function hasResult(){
63  return $this->result !== null;
64  }
65 
69  public function setResult($result){
70  $this->result = serialize($result);
71  }
72 
73  public function setTaskId($taskId){
74  $this->taskId = $taskId;
75  }
76 
77  public function getTaskId(){
78  return $this->taskId;
79  }
80 
86  public abstract function onRun();
87 
96  public function onCompletion(Server $server){
97 
98  }
99 
100 }
onCompletion(Server $server)
Definition: AsyncTask.php:96