Coroutine
Namespace:
namespace Lenga\Engine\Core;
class Coroutine
Methods
getId
public function getId()
isFinished
public function isFinished()
stop
public function stop()
matchesGenerator
public function matchesGenerator(\Generator $generator)
prime
public function prime()
tick
public function tick()
tickFixedUpdate
public function tickFixedUpdate()
Example
use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\WaitForSeconds;
class SequenceController extends Behaviour
{
public function start(): void
{
// Start a coroutine that will be managed automatically
$this->startCoroutine($this->playSequence());
}
private function playSequence(): \Generator
{
Debug::log('Sequence started');
yield new WaitForSeconds(1.0);
Debug::log('1 second has passed');
yield new WaitForSeconds(2.0);
Debug::log('3 seconds total have passed');
// Coroutine automatically finishes when generator ends
}
}