Barrier
in package
uses
ForbidCloning, ForbidSerialization
FinalYes
A barrier is a synchronization primitive.
The barrier is initialized with a certain count, which can be increased and decreased until it reaches zero.
A count of one can be used to block multiple coroutines until a certain condition is met.
A count of N can be used to await multiple coroutines doing an action to complete.
Example
$barrier = new Amp\Sync\Barrier(2);
$barrier->arrive();
$barrier->arrive(); // Barrier::await() returns immediately now
$barrier->await();
Table of Contents
Properties
- $completion : DeferredFuture
- $count : int
Methods
- __construct() : mixed
- __serialize() : never
- __unserialize() : never
- arrive() : void
- await() : void
- getCount() : int
- register() : void
- __clone() : mixed
Properties
$completion read-only
private
DeferredFuture
$completion
$count
private
int
$count
Methods
__construct()
public
__construct(positive-int $count) : mixed
Parameters
- $count : positive-int
__serialize()
public
final __serialize() : never
Return values
never__unserialize()
public
final __unserialize(array<string|int, mixed> $data) : never
Parameters
- $data : array<string|int, mixed>
Return values
neverarrive()
public
arrive([positive-int $count = 1 ]) : void
Parameters
- $count : positive-int = 1
await()
public
await([Cancellation|null $cancellation = null ]) : void
Parameters
- $cancellation : Cancellation|null = null
getCount()
public
getCount() : int
Return values
intregister()
public
register([positive-int $count = 1 ]) : void
Parameters
- $count : positive-int = 1
__clone()
protected
final __clone() : mixed