Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prism] Fix process timeouts between highlight calls for long building pages #138

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Highlighter/Prism.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
class Prism implements HighlighterInterface
{
private const IDLE_TIMEOUT = 60;

private string $executable;
private ?Process $server = null;
private ?InputStream $input = null;
Expand All @@ -37,12 +39,14 @@ public function start(): void
{
if (!$this->server) {
$this->input = new InputStream();
$this->server = new Process(['node', $this->executable], null, null, $this->input);
$this->server = new Process(['node', $this->executable], null, null, $this->input, null);
}

if (!$this->server->isRunning()) {
$this->server->start();
}

$this->server->setIdleTimeout(self::IDLE_TIMEOUT);
}

public function stop(): void
Expand Down Expand Up @@ -89,6 +93,10 @@ public function highlight(string $value, string $language): string
return false;
});

// Code highlight was processed.
// Let's remove the idle timeout for the running server until next call:
$this->server->setIdleTimeout(null);

if (isset($event)) {
$event->stop();
}
Expand Down