eee
This commit is contained in:
@@ -14,7 +14,7 @@ class CoroutineContext implements ContextInterface
|
||||
*/
|
||||
public static function inCoroutine(): bool
|
||||
{
|
||||
return true;
|
||||
return Coroutine::getCid() > -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,7 @@ class CoroutineContext implements ContextInterface
|
||||
*/
|
||||
public static function set(string $key, mixed $value, ?int $coroutineId = null): mixed
|
||||
{
|
||||
// TODO: Implement set() method.
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
return Coroutine::getContext($coroutineId)[$key] = $value;
|
||||
return Coroutine::getContext()[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,11 +37,7 @@ class CoroutineContext implements ContextInterface
|
||||
*/
|
||||
public static function get(string $key, mixed $defaultValue = null, ?int $coroutineId = null): mixed
|
||||
{
|
||||
// TODO: Implement get() method.
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
return Coroutine::getContext($coroutineId)[$key] ?? $defaultValue;
|
||||
return Coroutine::getContext()[$key] ?? $defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,11 +47,7 @@ class CoroutineContext implements ContextInterface
|
||||
*/
|
||||
public static function exists(string $key, ?int $coroutineId = null): bool
|
||||
{
|
||||
// TODO: Implement exists() method.
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
return isset(Coroutine::getContext($coroutineId)[$key]);
|
||||
return isset(Coroutine::getContext()[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,12 +57,8 @@ class CoroutineContext implements ContextInterface
|
||||
*/
|
||||
public static function remove(string $key, ?int $coroutineId = null): void
|
||||
{
|
||||
// TODO: Implement remove() method.
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
}
|
||||
Coroutine::getContext($coroutineId)[$key] = null;
|
||||
unset(Coroutine::getContext($coroutineId)[$key]);
|
||||
Coroutine::getContext()[$key] = null;
|
||||
unset(Coroutine::getContext()[$key]);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,13 +70,10 @@ class CoroutineContext implements ContextInterface
|
||||
*/
|
||||
public static function increment(string $id, int $value = 1, ?int $coroutineId = null): int
|
||||
{
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
if (!isset(Coroutine::getContext()[$id])) {
|
||||
Coroutine::getContext()[$id] = 0;
|
||||
}
|
||||
if (!isset(Coroutine::getContext($coroutineId)[$id])) {
|
||||
Coroutine::getContext($coroutineId)[$id] = 0;
|
||||
}
|
||||
return Coroutine::getContext($coroutineId)[$id] += $value;
|
||||
return Coroutine::getContext()[$id] += $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,12 +84,9 @@ class CoroutineContext implements ContextInterface
|
||||
*/
|
||||
public static function decrement(string $id, int $value = 1, ?int $coroutineId = null): int
|
||||
{
|
||||
if (is_null($coroutineId)) {
|
||||
$coroutineId = Coroutine::getCid();
|
||||
if (!isset(Coroutine::getContext()[$id])) {
|
||||
Coroutine::getContext()[$id] = 0;
|
||||
}
|
||||
if (!isset(Coroutine::getContext($coroutineId)[$id])) {
|
||||
Coroutine::getContext($coroutineId)[$id] = 0;
|
||||
}
|
||||
return Coroutine::getContext($coroutineId)[$id] -= $value;
|
||||
return Coroutine::getContext()[$id] -= $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user