Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Promise Examples

Doge edited this page Aug 31, 2021 · 4 revisions

Hello world

$promise = new Promise(
    function (): string {
        return "Hello world";
    }
);

$promise
    ->then(fn(string $response) => var_dump($response))
    ->settle();

JSON decoder

$promise = new Promise(
    function (): string {
        $person = [
            "name" => "john",
            "lastName" => "smith",
            "age" => 40
        ];

        return json_encode($person);
    }
);

$promise
    ->then(fn(string $response): array => json_decode($response, true))
    ->then(fn(array $response) => var_dump($response))
    ->settle();
Clone this wiki locally