PHP code example of chemem / asyncify

1. Go to this page and download the library: Download chemem/asyncify 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/ */

    

chemem / asyncify example snippets


use function Chemem\Asyncify\call;

$call = call('file_get_contents', ['foo.txt'])
  ->then(
    function (?string $contents) {
      echo $contents;
    },
    function (\Throwable $err) {
      echo $err->getMessage();
    }
  );

use Chemem\Asyncify\Async;

$exec = Async::create()
  ->call('file_get_contents', ['foo.txt'])
  ->then(
    function (?string $contents) {
      echo $contents;
    },
    function (\Throwable $err) {
      echo $err->getMessage();
    }
  );

namespace Chemem\Asyncify;

class Async {

  /* Methods */
  public static create( ?string $autoload = null [, ?React\EventLoop\LoopInterface $rootDir = null ] ) : Async;
  public function call( string $function [, array $args ] ) : React\Promise\PromiseInterface;
}

namespace Chemem\Asyncify;

call ( string $func [, array $args [, ?string $autoload = null [, ?React\EventLoop\LoopInterface $args = null ] ] ] ) : React\Promise\PromiseInterface;