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