Skip to content

Commit

Permalink
Fix closing of gif stream
Browse files Browse the repository at this point in the history
  • Loading branch information
igorw committed Nov 3, 2012
1 parent f76803e commit 47e8f26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/React/Gifsocket/GifStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public function resume()

public function close()
{
$data = $this->finish();
if ($this->closed) {
return;
}

$data = $this->encoder->finish();
$this->emit('data', [$data]);

$this->closed = true;
Expand Down
9 changes: 7 additions & 2 deletions src/React/Gifsocket/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ public function __invoke($request, $response)
$gif->pipe($response);

$this->gifStreams->attach($gif);
$request->on('close',
Curry::bind([$this->gifStreams, 'detach'], $gif));

$response->on('close', function () use ($gif) {
echo "response:close\n";

$this->gifStreams->detach($gif);
$gif->close();
});
}

public function resendFrame(GifStream $gif, $frame)
Expand Down

0 comments on commit 47e8f26

Please sign in to comment.