Bearsampp 2026.7.11
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

Internal: Single fiber module wrapper Manages lifecycle of a single module's fiber

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

Constructor & Destructor Documentation

◆ __construct()

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

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

187 {
188 $this->moduleName = $moduleName;
189 $this->timeout = $timeout;
190
191 // Create fiber (PHP 8.1+)
192 $this->fiber = new Fiber(function() use ($loader) {
193 try {
194 $this->result = call_user_func($loader);
195 $this->initialized = true;
196 } catch (Throwable $e) {
197 Log::error('Fiber error in ' . $this->moduleName . ': ' . $e->getMessage());
198 $this->initialized = true; // Mark as done even on error
199 }
200 });
201
202 // Start the fiber (begins execution until first yield)
203 try {
204 $this->fiber->start();
205 } catch (Throwable $e) {
206 Log::error('Failed to start fiber for ' . $this->moduleName . ': ' . $e->getMessage());
207 $this->initialized = true;
208 }
209 }
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 293 of file class.fibermoduleloader.php.

293 : string
294 {
295 return $this->moduleName;
296 }

References $moduleName.

◆ getResult()

getResult ( )

Get result from module loader

Returns
mixed The loader's return value

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

304 {
305 return $this->result;
306 }

References $result.

◆ isReady()

isReady ( )

Check if module is ready

Returns
bool True if loading complete

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

263 : bool
264 {
265 return $this->initialized || $this->fiber->isTerminated();
266 }

◆ isSuspended()

isSuspended ( )

Check if fiber is suspended (mid-execution)

Returns
bool True if suspended

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

273 : bool
274 {
275 return $this->fiber->isSuspended();
276 }

◆ isTerminated()

isTerminated ( )

Check if fiber is terminated

Returns
bool True if finished

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

283 : bool
284 {
285 return $this->fiber->isTerminated();
286 }

◆ 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 218 of file class.fibermoduleloader.php.

218 : bool
219 {
220 if ($this->initialized) {
221 return true;
222 }
223
224 $start = microtime(true);
225 $maxWait = $timeout / 1000;
226
227 while (!$this->initialized) {
228 // Try to resume the fiber if suspended
229 if ($this->fiber->isSuspended()) {
230 try {
231 $this->fiber->resume();
232 } catch (Throwable $e) {
233 Log::error('Fiber resume error: ' . $e->getMessage());
234 $this->initialized = true;
235 break;
236 }
237 }
238
239 // Check if fiber completed
240 if ($this->fiber->isTerminated()) {
241 $this->initialized = true;
242 break;
243 }
244
245 // Timeout check
246 if ((microtime(true) - $start) > $maxWait) {
247 Log::warning('Timeout waiting for module: ' . $this->moduleName);
248 return false;
249 }
250
251 // Prevent busy-waiting (yield to other operations)
252 usleep(1000);
253 }
254
255 return true;
256 }
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 180 of file class.fibermoduleloader.php.

◆ $initialized

$initialized = false
private

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

◆ $moduleName

$moduleName
private

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

Referenced by __construct(), and getModuleName().

◆ $result

$result = null
private

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

Referenced by getResult().

◆ $timeout

$timeout
private

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

Referenced by __construct(), and wait().


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