PHP code example of mcbeany / libasync

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

    

mcbeany / libasync example snippets


libAsync::doAsync(Closure $executor); // <-- Returns a promise

use SOFe/AwaitGenerator/Await;
use Mcbeany/libAsync/libAsync;
use pocketmine/utils/Internet;

Await::f2c(function(){
    $response = yield from libAsync::doAsync(fn() => Internet::getUrl("example.com"));
    var_dump($response);
});

Await::g2c(
    libAsync::doAsync(fn() => file_put_contents('file.txt', 'Hello World!')),
    fn() => $this->getLogger()->info("Saved file successfully!")
);