StreamChannel
in package
implements
Channel
uses
ForbidCloning, ForbidSerialization
FinalYes
An asynchronous channel for sending data between threads and processes.
Supports full duplex read and write.
Tags
Table of Contents
Interfaces
- Channel
- Interface for sending messages between execution contexts, such as two coroutines or two processes.
Properties
- $parser : ChannelParser
- $read : ReadableStream
- $readMutex : Mutex
- $received : SplQueue<string|int, TReceive>
- $write : WritableStream
Methods
- __construct() : mixed
- Creates a new channel from the given stream objects. Note that $read and $write can be the same object.
- __destruct() : mixed
- __serialize() : never
- __unserialize() : never
- close() : void
- Closes the read and write resource streams.
- isClosed() : bool
- Returns whether this resource has been closed.
- onClose() : void
- Registers a callback that is invoked when this resource is closed.
- receive() : TReceive
- send() : void
- __clone() : mixed
Properties
$parser read-only
private
ChannelParser
$parser
$read read-only
private
ReadableStream
$read
$readMutex read-only
private
Mutex
$readMutex
$received read-only
private
SplQueue<string|int, TReceive>
$received
$write read-only
private
WritableStream
$write
Methods
__construct()
Creates a new channel from the given stream objects. Note that $read and $write can be the same object.
public
__construct(ReadableStream $read, WritableStream $write[, Serializer|null $serializer = null ]) : mixed
Parameters
- $read : ReadableStream
- $write : WritableStream
- $serializer : Serializer|null = null
__destruct()
public
__destruct() : mixed
__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
neverclose()
Closes the read and write resource streams.
public
close() : void
isClosed()
Returns whether this resource has been closed.
public
isClosed() : bool
Return values
bool —true if closed, otherwise false.
onClose()
Registers a callback that is invoked when this resource is closed.
public
onClose(Closure $onClose) : void
Parameters
- $onClose : Closure
receive()
public
receive([Cancellation|null $cancellation = null ]) : TReceive
Parameters
- $cancellation : Cancellation|null = null
-
Cancels waiting for the next value. Note the next value is not discarded if the operation is cancelled, rather it will be returned from the next call to this method.
Return values
TReceive —Data received.
send()
public
send(mixed $data) : void
Parameters
- $data : mixed
__clone()
protected
final __clone() : mixed