PHP code example of reinfyteam / libvapm-pmmp

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

    

reinfyteam / libvapm-pmmp example snippets


use pocketmine\plugin\PluginBase;
use vennv\vapm\VapmPMMP;

final class Main extends PluginBase{
    protected function onEnable() : void{
        VapmPMMP::init($this);
    }
}

use vennv\vapm\VapmPMMP;
use vennv\vapm\io\Io;
use vennv\vapm\ct\Ct;
use vennv\vapm\Promise;
use vennv\vapm\System;

$job = Io::async(function () : string {
    return "done";
});

$result = Io::await($job); // "done"

Io::setTimeout(function () : void {
    // run once after delay
}, 50);

Io::setInterval(function () : void {
    // run repeatedly
}, 20);

Io::delay(100)->then(function () : void {
    // delayed promise flow
});

use Generator;

Ct::c(function () : Generator {
    yield from Ct::cDelay(10);
    // coroutine work
});

Ct::cBlock(function () : Generator {
    yield from Ct::cDelay(5);
    // blocking coroutine run
});

$all = Promise::all([
    Io::async(fn() => 1),
    Io::async(fn() => 2),
]);

$values = Io::await($all); // [1, 2]

System::fetch("https://example.com")->then(function ($response) : void {
    // InternetRequestResult
});

System::read("/path/to/file.txt")->then(function (string $content) : void {
    // file contents
});

Io::delay(100)->then(function () : void {
    // do primary operation
})->finally(function () : void {
    // cleanup
});

$task = System::setInterval(function () : void {
    // heartbeat
}, 20);

System::setTimeout(function () use ($task) : void {
    System::clearInterval($task);
}, 200);

$result = Io::await(Promise::all([
    Io::async(fn() => "A"),
    Io::async(fn() => "B"),
]));

System::fetch("https://example.com", [
    "method" => "GET",
    "timeout" => 5,
])->then(function ($response) : void {
    // InternetRequestResult
});