|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace parallel; |
| 4 | + |
| 5 | +/** |
| 6 | + * @template T |
| 7 | + */ |
| 8 | +final class Channel |
| 9 | +{ |
| 10 | + /** |
| 11 | + * Constant for Infinitely Buffered |
| 12 | + */ |
| 13 | + public const Infinite = -1; |
| 14 | + |
| 15 | + /* Anonymous Constructor */ |
| 16 | + |
| 17 | + /** |
| 18 | + * Shall make an anonymous unbuffered channel |
| 19 | + * Shall make an anonymous buffered channel with the given capacity |
| 20 | + * |
| 21 | + * @param null|int $capacity May be Channel::Infinite or a positive integer |
| 22 | + */ |
| 23 | + public function __construct(?int $capacity = null) {} |
| 24 | + |
| 25 | + /* Access */ |
| 26 | + |
| 27 | + /** |
| 28 | + * Shall make an unbuffered channel with the given name |
| 29 | + * Shall make a buffered channel with the given name and capacity |
| 30 | + * |
| 31 | + * @param string $name The name of the channel. |
| 32 | + * @param null|int $capacity May be Channel::Infinite or a positive integer |
| 33 | + * |
| 34 | + * @return Channel<T> |
| 35 | + * |
| 36 | + * @throws Channel\Error\Existence if channel already exists. |
| 37 | + */ |
| 38 | + public static function make(string $name, ?int $capacity = null): Channel {} |
| 39 | + |
| 40 | + /** |
| 41 | + * Shall open the channel with the given name |
| 42 | + * |
| 43 | + * @param string $name |
| 44 | + * @return Channel<T> |
| 45 | + * |
| 46 | + * @throws Channel\Error\Existence if channel does not exist. |
| 47 | + */ |
| 48 | + public static function open(string $name): Channel {} |
| 49 | + |
| 50 | + /* Sharing */ |
| 51 | + |
| 52 | + /** |
| 53 | + * Shall send the given value on this channel |
| 54 | + * @param T $value |
| 55 | + * |
| 56 | + * @throws Channel\Error\Closed if channel is closed. |
| 57 | + * @throws Channel\Error\IllegalValue if value is illegal. |
| 58 | + */ |
| 59 | + public function send($value): void {} |
| 60 | + |
| 61 | + /** |
| 62 | + * Shall recv a value from this channel |
| 63 | + * @return T |
| 64 | + * |
| 65 | + * @throws Channel\Error\Closed if channel is closed. |
| 66 | + */ |
| 67 | + public function recv() {} |
| 68 | + |
| 69 | + /* Closing */ |
| 70 | + |
| 71 | + /** |
| 72 | + * Shall close this channel |
| 73 | + * @throws Channel\Error\Closed if channel is closed. |
| 74 | + */ |
| 75 | + public function close(): void {} |
| 76 | + |
| 77 | + /** |
| 78 | + * Returns name of channel |
| 79 | + * @return string |
| 80 | + */ |
| 81 | + public function __toString(): string {} |
| 82 | +} |
0 commit comments