From 9b0cf98e10f494dea82629c6e2df4bc67d2348f4 Mon Sep 17 00:00:00 2001 From: Charlotte Dunois Date: Thu, 7 May 2020 14:44:00 +0200 Subject: [PATCH] Update tail example We need to open a file descriptor manually, as if we were to open a stream, the stream would read the complete file and then close the file descriptor. --- examples/tail.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/tail.php b/examples/tail.php index a790414b..09350111 100644 --- a/examples/tail.php +++ b/examples/tail.php @@ -12,14 +12,10 @@ echo $content; $lastSize = strlen($content); + $adapter = $filesystem->getAdapter(); - $file = $filesystem->file($path); - - $file->open('r')->then(function (\React\Stream\ReadableStreamInterface $stream) use ($filesystem, $loop, $file, &$lastSize) { - /** @var \React\Filesystem\Stream\GenericStreamInterface $stream */ - $fileDescriptor = $stream->getFiledescriptor(); - - $adapter = $filesystem->getAdapter(); + $adapter->open($path, 'r')->then(function ($fileDescriptor) use ($adapter, $filesystem, $loop, $path, &$lastSize) { + $file = $filesystem->file($path); $loop->addPeriodicTimer(1, function () use ($adapter, $fileDescriptor, $file, &$lastSize) { $file->size()->then(function ($size) use ($adapter, $fileDescriptor, &$lastSize) {