krinfreschi / async-streams
v0.0.3
2014-07-27 18:49 UTC
Requires
- react/event-loop: 0.4.*
This package is not auto-updated.
Last update: 2024-12-17 03:36:42 UTC
README
A stream wrapper around reactphp for async streams
With inspiration from guzzle/streams
##Installation
This package can be installed easily using Composer. Simply add the following to the composer.json file at the root of your project:
{ "require": { "krinfreschi/async-streams": "0.0.*" } }
Then install your dependencies using composer.phar install.
##Global Functions:
async_stream_register_read(resource $handle, callable $callable) //$callable will receive args: $handle async_stream_remove_read(resource $handle) async_stream_register_write(resource $handle, callable $callable) //$callable will receive args: $handle, $written, $unwritten async_stream_remove_write(resource $handle)
##Example:
use krinfreschi\AsyncStreams\AsyncStreamWrapper; require_once "vendor/autoload.php"; $resource = fopen('php://temp', 'r+'); $handle = AsyncStreamWrapper::make($resource); fwrite($handle, 'data'); async_stream_register_write($handle, function($handle, $written, $unwritten) { fseek($handle, 0); var_dump(stream_get_contents($handle)); fclose($handle); }); AsyncStreamWrapper::run();