innmind / async-stream
此包已被弃用且不再维护。作者建议使用 innmind/mantle 包代替。
1.0.0
2023-02-11 13:43 UTC
Requires
- php: ~8.1
- innmind/mantle: ~1.0
- innmind/stream: ^4.0
- innmind/time-continuum: ^3.1
Requires (Dev)
- innmind/black-box: ~4.10
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~9.0
- vimeo/psalm: ~4.30
This package is auto-updated.
Last update: 2023-11-06 06:40:49 UTC
README
这是 innmind/stream
的异步实现,允许在读取、写入或监听流时切换到其他任务。
安装
composer require innmind/async-stream
用法
use Innmind\Async\Stream\Streams; use Innmind\Stream\Streams as Synchronous; use Innmind\TimeContinuum\Earth\Clock; use Innmind\Url\Path; use Innmind\Mantle\{ Source\Predetermined, Suspend, Forerunner, }; $clock = new Clock; $synchronous = Synchronous::fromAmbientAuthority(); $source = Predetermined::of( static function(Suspend $suspend) use ($clock, $synchronous) { $stream = Streams::of($synchronous, $suspend, $clock) ->readable() ->open(Path::of('fixtures/first.txt')); while (!$stream->end()) { echo $stream->readLine()->match( static fn($line) => $line->toString(), static fn() => '', ); } }, static function(Suspend $suspend) use ($clock, $synchronous) { $stream = Streams::of($synchronous, $suspend, $clock) ->readable() ->open(Path::of('fixtures/second.txt')); while (!$stream->end()) { echo $stream->readLine()->match( static fn($line) => $line->toString(), static fn() => '', ); } }, ); Forerunner::of($clock)(null, $source); // will print interlaced lines of both files