| @@ 11-32 (lines=22) @@ | ||
| 8 | use React\Promise\CancellablePromiseInterface; |
|
| 9 | use function WyriHaximus\React\futureFunctionPromise; |
|
| 10 | ||
| 11 | final class JsonDecodeService implements ServiceInterface |
|
| 12 | { |
|
| 13 | /** |
|
| 14 | * @var LoopInterface |
|
| 15 | */ |
|
| 16 | private $loop; |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @param LoopInterface $loop |
|
| 20 | */ |
|
| 21 | public function __construct(LoopInterface $loop) |
|
| 22 | { |
|
| 23 | $this->loop = $loop; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function handle($input): CancellablePromiseInterface |
|
| 27 | { |
|
| 28 | return futureFunctionPromise($this->loop, $input, function ($json) { |
|
| 29 | return decode($json, true); |
|
| 30 | }); |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||
| @@ 12-37 (lines=26) @@ | ||
| 9 | use function React\Promise\resolve; |
|
| 10 | use function WyriHaximus\React\futureFunctionPromise; |
|
| 11 | ||
| 12 | final class JsonEncodeService implements ServiceInterface |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * @var LoopInterface |
|
| 16 | */ |
|
| 17 | private $loop; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * @param LoopInterface $loop |
|
| 21 | */ |
|
| 22 | public function __construct(LoopInterface $loop) |
|
| 23 | { |
|
| 24 | $this->loop = $loop; |
|
| 25 | } |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @param $input |
|
| 29 | * @return CancellablePromiseInterface |
|
| 30 | */ |
|
| 31 | public function handle($input): CancellablePromiseInterface |
|
| 32 | { |
|
| 33 | return futureFunctionPromise($this->loop, $input, function ($json) { |
|
| 34 | return encode($json); |
|
| 35 | }); |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||