class Coroutine implements CoroutineInterface

Methods

__construct(callable $callable)

Create a new coroutine instance.

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

Create and execute a new coroutine.

execute(mixed ...$data)

Execute the coroutine.

int
getId()

Get the coroutine ID.

static int
id()

Get the current coroutine ID.

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

Get the parent coroutine ID.

static void
set(array $config)

Set the coroutine configuration.

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

Get the coroutine context.

static void
defer(callable $callable)

Register a callback to be executed when the coroutine ends.

static bool
yield()

Yield the current coroutine.

static bool
resumeById(int $id)

Resume a coroutine by ID.

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

Cancel a coroutine by ID.

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

Wait for the given coroutines to finish.

static array
stats()

Get the coroutine statistics.

static bool
exists(int $id)

Determine if a coroutine exists.

static iterable
list()

Get all coroutine IDs.

Details

at line 27
__construct(callable $callable)

Create a new coroutine instance.

Parameters

callable $callable [required]

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

Create and execute a new coroutine.

Parameters

callable $callable
mixed ...$data

Return Value

CoroutineInterface

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

Execute the coroutine.

Parameters

mixed ...$data

Return Value

CoroutineInterface

at line 63
int getId()

Get the coroutine ID.

Return Value

int

at line 74
static int id()

Get the current coroutine ID.

Return Value

int

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

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

Get the parent coroutine ID.

Parameters

int|null $id

Return Value

int

at line 104
static void set(array $config)

Set the coroutine configuration.

Boot-only. Mutates Swoole's process-global coroutine configuration; calling this per-request changes settings for every concurrent coroutine in the worker.

Parameters

array $config

Return Value

void

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

Get the coroutine context.

Parameters

int|null $id

coroutine id

Return Value

ArrayObject|null

at line 124
static void defer(callable $callable)

Register a callback to be executed when the coroutine ends.

Parameters

callable $callable

Return Value

void

at line 132
static bool yield()

Yield the current coroutine.

Return Value

bool

at line 140
static bool resumeById(int $id)

Resume a coroutine by ID.

Parameters

int $id

Return Value

bool

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

Cancel a coroutine by ID.

Parameters

int $id
bool $throwException

Return Value

bool

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

Wait for the given coroutines to finish.

Parameters

array $coroutineIds
float $timeout

Return Value

bool

at line 166
static array stats()

Get the coroutine statistics.

Return Value

array

at line 174
static bool exists(int $id)

Determine if a coroutine exists.

Parameters

int $id

Return Value

bool

at line 184
static iterable list()

Get all coroutine IDs.

Return Value

iterable

returns all coroutine IDs