Bearsampp 2026.9.23
Loading...
Searching...
No Matches
FiberModule Class Reference

Public Member Functions

 __construct (string $moduleName, callable $loader, int $timeout=5000)
 getModuleName ()
 getResult ()
 isReady ()
 isSuspended ()
 isTerminated ()
 wait (int $timeout=5000)

Private Attributes

 $fiber
 $initialized = false
 $moduleName
 $result = null
 $timeout

Detailed Description

Class FiberModule

Internal single-fiber module wrapper. Manages the lifecycle of one module's fiber.

Definition at line 191 of file class.fibermoduleloader.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( string $moduleName,
callable $loader,
int $timeout = 5000 )

FiberModule constructor.

Creates and starts the fiber that runs the loader callback.

Parameters
string$moduleNameThe module name this fiber loads.
callable$loaderThe callback that loads the module.
int$timeoutMaximum wait time in milliseconds.

Definition at line 217 of file class.fibermoduleloader.php.

218 {
219 $this->moduleName = $moduleName;
220 $this->timeout = $timeout;
221
222 // Create fiber (PHP 8.1+)
223 $this->fiber = new Fiber(function () use ($loader) {
224 try {
225 $this->result = call_user_func($loader);
226 $this->initialized = true;
227 } catch (Throwable $e) {
228 Log::error('Fiber error in ' . $this->moduleName . ': ' . $e->getMessage());
229 $this->initialized = true; // Mark as done even on error
230 }
231 });
232
233 // Start the fiber (begins execution until first yield)
234 try {
235 $this->fiber->start();
236 } catch (Throwable $e) {
237 Log::error('Failed to start fiber for ' . $this->moduleName . ': ' . $e->getMessage());
238 $this->initialized = true;
239 }
240 }
static error($data, $file=null)

References $moduleName, $timeout, and Log\error().

Here is the call graph for this function:

Member Function Documentation

◆ getModuleName()

getModuleName ( )

Get module name

Returns
string Module name

Definition at line 326 of file class.fibermoduleloader.php.

326 : string
327 {
328 return $this->moduleName;
329 }

References $moduleName.

◆ getResult()

getResult ( )

Get result from module loader

Returns
mixed The loader's return value

Definition at line 336 of file class.fibermoduleloader.php.

337 {
338 return $this->result;
339 }

References $result.

◆ isReady()

isReady ( )

Check if module is ready

Returns
bool True if loading complete

Definition at line 296 of file class.fibermoduleloader.php.

296 : bool
297 {
298 return $this->initialized || $this->fiber->isTerminated();
299 }

◆ isSuspended()

isSuspended ( )

Check if fiber is suspended (mid-execution)

Returns
bool True if suspended

Definition at line 306 of file class.fibermoduleloader.php.

306 : bool
307 {
308 return $this->fiber->isSuspended();
309 }

◆ isTerminated()

isTerminated ( )

Check if fiber is terminated

Returns
bool True if finished

Definition at line 316 of file class.fibermoduleloader.php.

316 : bool
317 {
318 return $this->fiber->isTerminated();
319 }

◆ wait()

wait ( int $timeout = 5000)

Wait for module to finish loading Returns immediately if already done

Parameters
int$timeoutMaximum wait time (ms)
Returns
bool True if loaded, false if timeout

Definition at line 250 of file class.fibermoduleloader.php.

250 : bool
251 {
252 if ($this->initialized) {
253 return true;
254 }
255
256 $start = microtime(true);
257 $maxWait = $timeout / 1000;
258
259 while (!$this->initialized) {
260 // Try to resume the fiber if suspended
261 if ($this->fiber->isSuspended()) {
262 try {
263 $this->fiber->resume();
264 } catch (Throwable $e) {
265 Log::error('Fiber resume error: ' . $e->getMessage());
266 $this->initialized = true;
267 break;
268 }
269 }
270
271 // Check if fiber completed
272 if ($this->fiber->isTerminated()) {
273 $this->initialized = true;
274 break;
275 }
276
277 // Timeout check
278 if ((microtime(true) - $start) > $maxWait) {
279 Log::warning('Timeout waiting for module: ' . $this->moduleName);
280
281 return false;
282 }
283
284 // Prevent busy-waiting (yield to other operations)
285 usleep(1000);
286 }
287
288 return true;
289 }
static warning($data, $file=null)

References $timeout, Log\error(), and Log\warning().

Here is the call graph for this function:

Field Documentation

◆ $fiber

$fiber
private

Definition at line 194 of file class.fibermoduleloader.php.

◆ $initialized

$initialized = false
private

Definition at line 200 of file class.fibermoduleloader.php.

◆ $moduleName

$moduleName
private

Definition at line 197 of file class.fibermoduleloader.php.

Referenced by __construct(), and getModuleName().

◆ $result

$result = null
private

Definition at line 203 of file class.fibermoduleloader.php.

Referenced by getResult().

◆ $timeout

$timeout
private

Definition at line 206 of file class.fibermoduleloader.php.

Referenced by __construct(), and wait().


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