Skip to content

Commit

Permalink
Add sleeps to optimise CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed May 29, 2024
1 parent cfd9c00 commit 3546e39
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Components/InteractiveComponentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private function applyKey(InteractiveComponent $component, array $validation): m
[$keyBindings, $inputHandlers] = $this->resolveHandlers($component);

while (true) {
usleep(5000);
$key = fread(STDIN, 16);

// If there's no keypress, continue
Expand Down Expand Up @@ -135,6 +136,8 @@ private function applyKey(InteractiveComponent $component, array $validation): m
private function renderFrames(InteractiveComponent $component, Terminal $terminal): mixed
{
while (true) {
usleep(5000);

// If there are no updates,
// we won't spend time re-rendering the same frame
if (! $this->shouldRerender) {
Expand Down

0 comments on commit 3546e39

Please sign in to comment.