Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
VennDev authored Sep 6, 2023
1 parent 1a25a1e commit 54c4ebe
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions some_tests/promise-async-await/PromiseAll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';

use vennv\vapm\simultaneous\Promise;
use vennv\vapm\System;

/**
* @throws Throwable
*/
function testPromise1() : Promise {
return new Promise(function ($resolve, $reject) {
System::setTimeout(function () use ($resolve) {
$resolve("A");
}, 1000);
});
}

/**
* @throws Throwable
*/
function testPromise2() : Promise {
return new Promise(function ($resolve, $reject) {
System::setTimeout(function () use ($reject) {
$reject("B");
}, 1000);
});
}

/**
* @throws Throwable
*/
function main() : void {
Promise::all([
testPromise1(),
testPromise2(),
])
->then(function ($values) {
var_dump($values);
})
->catch(function ($reason) {
var_dump($reason);
});
}

main();

0 comments on commit 54c4ebe

Please sign in to comment.