php-etl / promise
Promise implementation for ETL usage.
Installs: 174
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
pkg:composer/php-etl/promise
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: 2025-10-06 21:10:56 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; } );