_callback = $callback; $this->_closed = false; $this->_buffer = []; } public function closed(): bool { return $this->_closed; } public function get(): ?array { if ($this->_closed) { return null; } if (sizeof($this->_buffer) == 0) { // Fill more data $callback = $this->_callback; $this->_buffer = $callback(); if (sizeof($this->_buffer) == 0) { $this->_closed = true; return null; } } return array_shift($this->_buffer); } }