PHP code example of innmind / async-operating-system

1. Go to this page and download the library: Download innmind/async-operating-system 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/ */

    

innmind / async-operating-system example snippets


use Innmind\Async\OperatingSystem\Factory;
use Innmind\OperatingSystem\Factory as Synchronous;
use Innmind\Filesystem\Name;
use Innmind\Http\{
    Message\Request\Request,
    Message\Method,
    ProtocolVersion,
};
use Innmind\Url\{
    Url,
    Path,
};
use Innmind\Mantle\{
    Source\Predetermined,
    Suspend,
    Forerunner,
};

$synchronous = Synchronous::build();
$factory = Factory::of($synchronous);
$source = Predetermined::of(
    static fn(Suspend $suspend) => $factory
        ->build($suspend)
        ->filesystem()
        ->mount(Path::of('somewhere/'))
        ->get(Name::of('some-file'))
        ->match(
            static fn($file) => doYourStuff($file),
            static fn() => null,
        ),
    static fn(Suspend $suspend) => $factory
        ->build($suspend)
        ->remote()
        ->http()(new Request(
            Url::of('https://wikipedia.org')
            Method::get,
            ProtocolVersion::v11,
        ))
        ->match(
            static fn($success) => doYourStuff($success),
            static fn() => null,
        );
);

Forerunner::of($synchronous->clock())(null, $source);