Changeset View
Changeset View
Standalone View
Standalone View
scripts/test/progress_bar.php
Show All 37 Lines | echo "\n".pht( | ||||
"This bar will be interrupted by an exception.\n". | "This bar will be interrupted by an exception.\n". | ||||
"It should clean itself up.")."\n"; | "It should clean itself up.")."\n"; | ||||
try { | try { | ||||
run_interrupt_bar(); | run_interrupt_bar(); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
echo pht('Caught exception!')."\n"; | echo pht('Caught exception!')."\n"; | ||||
} | } | ||||
echo "\n".pht( | |||||
"RESIZING BARS\n". | |||||
"If you resize the window while a progress bars draws, it should more or ". | |||||
"less detect the change."); | |||||
$n = 1024; | |||||
$bar = id(new PhutilConsoleProgressBar()) | |||||
->setTotal($n); | |||||
for ($ii = 0; $ii < $n; $ii++) { | |||||
$bar->update(1); | |||||
usleep(10000); | |||||
} | |||||
$bar->done(); | |||||
function run_interrupt_bar() { | function run_interrupt_bar() { | ||||
$bar = id(new PhutilConsoleProgressBar()) | $bar = id(new PhutilConsoleProgressBar()) | ||||
->setTotal(100); | ->setTotal(100); | ||||
for ($ii = 0; $ii < 100; $ii++) { | for ($ii = 0; $ii < 100; $ii++) { | ||||
if ($ii === 20) { | if ($ii === 20) { | ||||
throw new Exception(pht('Boo!')); | throw new Exception(pht('Boo!')); | ||||
} | } | ||||
$bar->update(1); | $bar->update(1); | ||||
usleep(10000); | usleep(10000); | ||||
} | } | ||||
} | } |