Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
VennDev authored Jul 9, 2023
1 parent 9b9cd57 commit a44e5b1
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,44 +198,50 @@ System::endSingleJob();
```
- Chaining Promises:
```php
function promise1() : Promise {
return new Promise(function($resolve, $reject) {
System::setTimeout(function() use ($resolve) {
$resolve("promise1");
}, 5000);
function testPromise1() : Promise {
return new Promise(function ($resolve, $reject) {
System::setTimeout(function () use ($resolve) {
$resolve("A");
}, 1000);
});
}

function promise2() : Promise {
return new Promise(function($resolve, $reject) {
System::setTimeout(function() use ($resolve) {
$resolve("promise2");
}, 3000);
function testPromise2() : Promise {
return new Promise(function ($resolve, $reject) {
System::setTimeout(function () use ($resolve) {
$resolve("B");
}, 1000);
});
}

function promise3() : Promise {
return new Promise(function($resolve, $reject) {
System::setTimeout(function() use ($resolve) {
$resolve("promise3");
}, 3000);
function testPromise3() : Promise {
return new Promise(function ($resolve, $reject) {
System::setTimeout(function () use ($resolve) {
$resolve("C");
}, 1000);
});
}

function asyncTest() {
new Async(function() {
$time = microtime(true);
$promise = Async::await(Promise::all([
promise1(),
promise2(),
promise3()
]));
var_dump(microtime(true) - $time);
var_dump($promise);
function testPromise4() : Promise {
return new Promise(function ($resolve, $reject) {
System::setTimeout(function () use ($resolve) {
$resolve("D");
}, 1000);
});
}

asyncTest();
testPromise1()->then(function ($value) {
var_dump($value);
return testPromise2();
})->then(function ($value) {
var_dump($value);
return testPromise3();
})->then(function ($value) {
var_dump($value);
return testPromise4();
})->then(function ($value) {
var_dump($value);
});

System::endSingleJob();
```
Expand Down

0 comments on commit a44e5b1

Please sign in to comment.