Skip to content

Commit c9cabf9

Browse files
committed
Add WritableStream which is useful for sinks
1 parent 02191f4 commit c9cabf9

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

ThroughStream.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace React\Stream;
44

5-
use Evenement\EventEmitter;
6-
75
class ThroughStream extends ReadableStream implements WritableStreamInterface
86
{
97
private $pipeSource;

WritableStream.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace React\Stream;
4+
5+
use Evenement\EventEmitter;
6+
7+
class WritableStream extends EventEmitter implements WritableStreamInterface
8+
{
9+
public $closed = false;
10+
private $pipeSource;
11+
12+
public function __construct()
13+
{
14+
$this->on('pipe', array($this, 'handlePipeEvent'));
15+
}
16+
17+
public function handlePipeEvent($source)
18+
{
19+
$this->pipeSource = $source;
20+
}
21+
22+
public function write($data)
23+
{
24+
}
25+
26+
public function end($data = null)
27+
{
28+
if (null !== $data) {
29+
$this->write($data);
30+
}
31+
32+
$this->close();
33+
}
34+
35+
public function isWritable()
36+
{
37+
return !$this->closed;
38+
}
39+
40+
public function close()
41+
{
42+
if ($this->closed) {
43+
return;
44+
}
45+
46+
$this->closed = true;
47+
$this->emit('end', array($this));
48+
$this->emit('close', array($this));
49+
$this->removeAllListeners();
50+
}
51+
}

0 commit comments

Comments
 (0)