interface CoroutineInterface

Methods

__construct(callable $callable)

No description

execute(mixed ...$data)

No description

int
getId()

Get the coroutine ID.

create(callable $callable, mixed ...$data)

Create and execute a new coroutine.

static int
id()

No description

static int
pid(int|null $id = null)

Returns the parent coroutine ID.

static void
set(array $config)

Set the process-wide coroutine configuration.

static ArrayObject|null
getContextFor(int|null $id = null)

No description

static void
defer(callable $callable)

Execute callback when coroutine destruct.

static bool
yield()

Yield the current coroutine.

static bool
resumeById(int $id)

Resume the coroutine by coroutine ID.

static bool
cancelById(int $id, bool $throwException = false)

Cancel the coroutine by coroutine ID.

static bool
join(array $coroutineIds, float $timeout = -1)

Wait for the given coroutines to finish.

static array
stats()

Get the coroutine stats.

static bool
exists(int $id)

Check if a coroutine exists or not.

static iterable
list()

No description

Details

at line 16
__construct(callable $callable)

No description

Parameters

callable $callable [required]

at line 18
CoroutineInterface execute(mixed ...$data)

No description

Parameters

mixed ...$data

Return Value

CoroutineInterface

at line 23
int getId()

Get the coroutine ID.

Return Value

int

at line 28
static CoroutineInterface create(callable $callable, mixed ...$data)

Create and execute a new coroutine.

Parameters

callable $callable
mixed ...$data

Return Value

CoroutineInterface

at line 33
static int id()

No description

Return Value

int

returns coroutine id from current coroutine, -1 in non coroutine environment

at line 41
static int pid(int|null $id = null)

Returns the parent coroutine ID.

Returns 0 when running in the top level coroutine.

Parameters

int|null $id

Return Value

int

Exceptions

RunningInNonCoroutineException
CoroutineDestroyedException

at line 49
static void set(array $config)

Set the process-wide coroutine configuration.

Boot-only. The configuration affects every coroutine subsequently created in the worker process.

Parameters

array $config

Return Value

void

at line 54
static ArrayObject|null getContextFor(int|null $id = null)

No description

Parameters

int|null $id

coroutine id

Return Value

ArrayObject|null

at line 59
static void defer(callable $callable)

Execute callback when coroutine destruct.

Parameters

callable $callable

Return Value

void

at line 64
static bool yield()

Yield the current coroutine.

Return Value

bool

at line 69
static bool resumeById(int $id)

Resume the coroutine by coroutine ID.

Parameters

int $id

Return Value

bool

at line 74
static bool cancelById(int $id, bool $throwException = false)

Cancel the coroutine by coroutine ID.

Parameters

int $id
bool $throwException

Return Value

bool

at line 84
static bool join(array $coroutineIds, float $timeout = -1)

Wait for the given coroutines to finish.

A false return may mean that no supplied coroutine remained active or that the timeout elapsed. It is not a general failure signal.

Parameters

array $coroutineIds
float $timeout

Return Value

bool

at line 89
static array stats()

Get the coroutine stats.

Return Value

array

at line 94
static bool exists(int $id)

Check if a coroutine exists or not.

Parameters

int $id

Return Value

bool

at line 99
static iterable list()

No description

Return Value

iterable

returns all coroutine IDs