php-etl / promise
Promise implementation for ETL usage.
0.1.0
2019-10-28 08:14 UTC
Requires
- php: ^7.2
Requires (Dev)
- ext-xdebug: *
- drupol/phpspec-code-coverage: ^4.0@dev
- infection/infection: dev-master
- phpspec/phpspec: ^5.1
- phpstan/phpstan: ^0.12.0@dev
This package is auto-updated.
Last update: 2024-11-06 19:14:54 UTC
README
The Promise pattern is helping when you need to organise your callbacks for when some tasks must be executed later.
Assuming we have this class with a doSomethingAsync
method
that will produce later an call to onSuccess
event handler.
<?php use Kiboko\Component\ETL\Promise\DeferredInterface; use Kiboko\Component\ETL\Promise\Promise; use Kiboko\Component\ETL\Promise\PromiseInterface; class SomeEvent { public $value; } class AsyncTask { /** @var PromiseInterface */ private $promise; public function doSomethingAsync(): DeferredInterface { // Do something $this->promise = new Promise(); return $this->promise->defer(); } public function onSuccess(SomeEvent $event) { $this->promise->resolve($event->value); } }
You can then register the following
<?php $task = new AsyncTask(); $task ->doSomethingAsync() ->then( function(string $value) { echo $value; return $value; } );