Commits

Thomas Weinert committed 01f5e5d

Remove file delivery interval using an callback on the promise, Fix error response constructor

Comments (0)

Files changed (2)

src/Carica/Io/Network/Http/Response/Content/File.php

       if ($file = $this->fileSystem()->getFileResource($this->_filename)) {
         $defer = new Io\Deferred();
         $bytes = $this->_bufferSize;
-        $loop = $this->loop();
+        $that = $this;
         $interval = $this->loop()->setInterval(
-          function () use ($file, $bytes, $defer, $connection, $loop, $interval) {
+          function () use ($file, $bytes, $defer, $connection) {
             if ($connection->isActive() && is_resource($file)) {
               if (feof($file)) {
                 $defer->resolve();
             } else {
               $defer->reject();
             }
-            $loop->remove($interval);
           },
           100
         );
+        $defer->always(
+          function () use ($that, $interval) {
+            $that->loop()->remove($interval);
+          }
+        );
         return $defer->promise();
       }
       return FALSE;

src/Carica/Io/Network/Http/Response/Error.php

         </body>
       </html>';
 
-    public function __construct(Http\Connection $connection, $status = 500, $message = NULL) {
-      parent::__construct($connection);
+    public function __construct(Http\Request $request, $status = 500, $message = NULL) {
+      parent::__construct($request->connection());
       $this->setStatus($status);
       $this->content = new Http\Response\Content\Html();
       if (NULL === $message) {