Vapm
  • About
    • Why is it called unblocking?
    • Next update?
    • Credit
    • Info
  • System
    • runEventLoop()
    • runSingleEventLoop()
    • setTimeout()
    • setInterval()
    • fetch()
    • read()
    • time() & timeEnd()
  • Asynchronous
    • getId()
    • await()
  • Promise
    • c()
    • getId()
    • getFiber()
    • isJustGetResult()
    • getTimeOut()
    • getTimeStart()
    • getTimeEnd()
    • setTimeEnd()
    • canDrop()
    • getStatus()
    • getResult()
    • getReturn()
    • getCallback()
    • resolve() & reject()
    • then() & catch() & finally()
    • useCallbacks()
    • all()
    • allSettled()
    • any()
    • race()
    • Some common methods
  • CoroutineGen
    • runBlocking()
    • runNonBlocking()
    • Deferred
    • Deferred Await All
    • repeat() & delay()
    • Channel
      • Example about Channel
    • AwaitGroup
      • Example
    • Mutex
      • Example
    • Goroutine vs CoroutineGen
      • Concurrency
  • Thread
    • How do I create a thread?
    • How do I share data between threads?
    • Advanced Thread
  • Worker
    • Example
  • Stream
    • read()
    • write()
    • append()
    • delete()
    • create()
    • overWrite()
  • FAQ
    • Why System::runEventLoop() and System::runSingleEventLoop() ?
    • Do you want concurrency?
  • PocketMine-PMMP
Powered by GitBook
On this page
  1. Thread

Advanced Thread

You can use Thread as a waiting task with the Async function.

new Async(function() {
    $threads = [
        new MyThreadA(),
        new MyThreadB(),
        new MyThreadC()
    ];
    
    foreach ($threads as $thread) {
        $data = Async::await($thread->start());
        echo $data;
    }
});

Or

$class = new TestThread();
$class->start()->then(function ($data) {
    echo "Thread finished: " . implode(", ", $data) . "\n";
})->catch(function (Throwable $e) {
    echo "Thread failed: " . $e->getMessage() . "\n";
})->finally(function () {
    echo "Thread finished\n";
});
PreviousHow do I share data between threads?NextWorker

Last updated 9 months ago