PHP code example of adamnicholson / kyew

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

    

adamnicholson / kyew example snippets


$task = $kyew->async(function () {
    // Do some slow I/O operation
    return 'foo';
});
$response = $task->await(); // (string) "foo"

$google = $kyew->async(function () {
    return file_get_contents('http://google.com');
});

$bbc = $kyew->async(function () {
    return file_get_contents('http://bbc.co.uk');
});

// Both closures have already started executing in the background

$google->await(); // (string) HTML source for Google's homepage 
$bbc->await(); // (string) HTML source for BBC's homepage 

$pubsub = new Kyew\PubSub\InMemoryPubSub;
$kyew = new Kyew\Kyew(
    $pubsub,
    new Kyew\Queue\SynchronousQueue($pubsub)
);

$task = $this->kyew->async(function () {
    return 'Some return value!!!';
});
echo $task->await(); // string 'Some return value!!!'

$task = $kyew->async(function () {
    // Do some slow I/O operation
    return 'foo';
});

$response = $task->await();
echo $response; // (string) "foo"