legionth / reactphp-progressbar
A way to create a progressbar stream with ReactPHP
Requires
- react/stream: ^1.0
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-11-29 05:03:57 UTC
README
An event-driven progressbar stream that can be added to other streams to show its current progress.
Table of Contents
Usage
This stream can be integrate like any other ReactPHP Stream
$loop = Factory::create(); $progressBarStream = new ProgressbarStream(); $input = new React\Stream\WritableResourceStream(STDOUT, $loop); $output = new React\Stream\ReadableResourceStream(STDIN, $loop); $output->pipe($progressBarStream); $progressBarStream->on('error', function ($errorMessage) { echo $errorMessage; }); $progressBarStream->on('data', function ($progressBarString) use ($input) { $input->write($progressBarString . PHP_EOL); }); $loop->addPeriodicTimer(1, function () use ($output) { $output->emit('data', array(1)); }); $loop->addPeriodicTimer(3, function () use ($output) { $output->emit('data', array(10)); }); $loop->run();
This example will update the progressbar every 1 second by 1 unit/percent and every 3 seconds by 10 units/percent. This example can be found in the examples folder.
The progressbar stream will never overflow the maximum value. The stream will end if the current value reaches or goes beyond the maximum value.
data-Event
The data
event contains the visualization of the progress bar.
The data emitted by this event is a string.
This event will be emitted if the progressbar is updated.
currentValue-Event
The currentValue
event contains the integer value of the current progressbar.
This event will be emitted if the progressbar is updated.
maximumValue-Event
The maximumValue
event contains the integer value of the maximum reachable value
of the progressbar.
This event will be emitted if the progressbar is updated.
Installation
The recommended way to install this library is through Composer. New to Composer?
This will install the latest supported version:
$ composer require legionth/progressbar:^1.0