PHP code example of php-etl / promise

1. Go to this page and download the library: Download php-etl/promise library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-etl / promise example snippets




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);
    }
}


$task = new AsyncTask();
$task
    ->doSomethingAsync()
    ->then(
        function(string $value) {
            echo $value;
            return $value;
        }
    );