Skip to content

Commit

Permalink
Add reference and unreference methods to ResourceInputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jun 23, 2017
1 parent b67358a commit 704adf7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/ResourceInputStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ public function getResource() {
return $this->resource;
}

/**
* References the read watcher, so the loop keeps running in case there's an active read.
*
* @see Loop::reference()
*/
public function reference() {
if (!$this->resource) {
throw new \Error("Resource has already been freed");
}

Loop::reference($this->watcher);
}

/**
* Unreferences the read watcher, so the loop doesn't keep running even if there are active reads.
*
* @see Loop::unreference()
*/
public function unreference() {
if (!$this->resource) {
throw new \Error("Resource has already been freed");
}

Loop::unreference($this->watcher);
}

public function __destruct() {
if ($this->resource !== null) {
$this->free();
Expand Down

0 comments on commit 704adf7

Please sign in to comment.