Method
phasync::writable
Suspends the coroutine until the stream can be written without blocking, and returns the stream.
Description#
public static phasync::writable(
mixed $resource,
float $timeout = PHP_FLOAT_MAX
): mixedAs phasync::readable does for reading. One coroutine at a time may wait to write to a stream, while another waits to read from it.
Parameters#
- $resource mixed
- A stream
- $timeout float = PHP_FLOAT_MAX
- Seconds to wait at most
Return values#
$resource, for use in the call that writes it mixed
Errors / Exceptions#
| Exception | When |
|---|---|
IOException | If $resource is not an open stream, or is closed while waiting |
LogicException | If another coroutine is waiting to write to $resource |
TimeoutException | If the stream is not writable in time |
Examples#
stream_set_blocking($socket, false);
$written = fwrite(phasync::writable($socket), $data); // may write less than all of $dataSee also#
phasync::readableSuspends the coroutine until the stream can be read without blocking, and returns the stream.