This is automatic generated document for things in Swow\Coroutine class
Class Coroutine
Coroutine class is the abstract of coroutine.
A coroutine is a subroutine actively suspend itself, and get resumed when there is no other running coroutines, it’s co-operative so it was called co-routine.
We call suspending self “yield”, when yielding form a coroutine, the coroutine suspends its execution, the scheduler will find and execute another coroutine can continue.
Swow have hooked most of IO operation functions in PHP, an IO coroutine will yield when calling these functions. When the IO operation is done, and current coroutine yield, the scheduler may continue the fore-mentioned IO coroutine. This is how Swow make IO concurrency.
Constants
Methods
Static method count
Static method get
Static method getAll
Static method getCurrent
Get current coroutine
Static method getGlobalSwitches
Static method getMain
Get main (the most outter) coroutine
Static method killAll
Static method registerDeadlockHandler
Static method run
Create a coroutine and run it immediately
context swap happens here
Param callable
$callable the coroutine body Param mixed
$data arguments passed to the callable
Returns static
the new created coroutine
Static method yield
Yield from current coroutine
context swap happens here when success
Method __construct
Method __debugInfo
Returns array<string, mixed>
debug information for var_dump
Method call
Method eval
evaluate code in specified scope
Todo string $string? why not rename it to $code See Coroutine::getTrace() for $level
params usage
Param string
$string code to evaluate
Method getDefinedVars
get defined variables in specified scope
See Coroutine::getTrace() for params usage
Method getElapsed
Method getElapsedAsString
Method getEndTime
Method getExecutedFilename
get current executed code file name
See Coroutine::getTrace() for params usage
Method getExecutedFunctionName
get executed function name
See Coroutine::getTrace() for params usage
Method getExecutedLineno
get current executed code line
See Coroutine::getTrace() for params usage
Method getExitStatus
Method getId
Get unique coroutine id
Method getPrevious
Get previous coroutine
Method getStartTime
Method getState
Get coroutine state
Returns int
the enum number: static::STATE_* constants
Method getStateName
Method getSwitches
Method getTrace
get trace information
positive $level
value count frame from current to top, negative $level
value count frame from top to current.
for example, a stack may be like:
$level | frame | getTrace(0, 0) | getTrace(-1, 0) or getTrace(4, 0) | getTrace(0, 3) |
---|---|---|---|---|
5 | {main} | starts here | starts here | FIXME: main? |
4 / -1 | Swow\Coroutine::run(‘a’) | ends here | ||
3 / -2 | a() | |||
2 / -3 | b() | starts here | ||
1 / -4 | c() | |||
0 / -5 | Swow\Coroutine->getTraceAsString() | ends here | ends here |
Param int
$level trace start level Param int
$limit trace max length, negative or 0 meaning no limit Param int
$options trace options, same as debug_backtrace
options { @see https://www.php.net/manual/en/function.debug-backtrace.php }
Method getTraceAsList
get trace information as string like original php strack trace format in array
return value maybe like
[
"#0 some.php(7): Swow\Coroutine->getTraceAsString()",
"#1 some.php(10): c()",
"#2 some.php(13): b()",
"#3 [internal function]: a(1, 'some str', Array)",
"#4 some.php(16): Swow\Coroutine::run('a', 1, 'some str', Array)",
"#5 {main}",
]
See Coroutine::getTrace() for params usage
Method getTraceAsString
get trace information as string like original php strack trace format
return value maybe like
#0 some.php(7): Swow\Coroutine->getTraceAsString()
#1 some.php(10): c()
#2 some.php(13): b()
#3 [internal function]: a(1, 'some str', Array)
#4 some.php(16): Swow\Coroutine::run('a', 1, 'some str', Array)
#5 {main}
See Coroutine::getTrace() for params usage
Method getTraceDepth
get trace depth
See Coroutine::getTrace() for params usage
Method isAlive
Method isAvailable
Method isExecuting
Method kill
Method resume
Resume coroutine execution
context swap happens here when success
Method setLocalVar
set variable in specified scope
See Coroutine::getTrace() for $level
params usage
Param string
$name variable name Param mixed
$value variable value Param bool
$force force rebuild symbol table, if you donot know this, keep its default value