WyriHaximus · GitHub

@WyriHaximus

azjezz

@WyriHaximus

clue

@WyriHaximus

azjezz

By making this change `async()` can now also by used in event loop callbacks such as timers:
```php
Loop::addTimer(0.01, async(function () {
    echo 'Sleeping for one second';
    await(asleep(1));
    echo 'Waking up again';
}));
```
With this change, current `async()` usage changes from:
```php
async(function () {
   //
});
```
To:
```php
async(function () {
   //
})();
```

@WyriHaximus

clue

clue approved these changes Dec 24, 2021

@WyriHaximus

@WyriHaximus

This was referenced

Jan 25, 2022

Merged

Closed

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Feb 20, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

Merged

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Feb 21, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Feb 21, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Feb 24, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Feb 24, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Mar 2, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Mar 3, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Mar 3, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Mar 4, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

WyriHaximus added a commit to WyriHaximus-labs/async that referenced this pull request

Mar 4, 2022
Since `async()` returns a promise and those are normally cancelable, implementing this puts them in line with the rest of our ecosystem. As such the following example will throw a timeout exception from the canceled `sleep()` call.
```php
$promise = async(static function (): int {
    echo 'a';
    await(sleep(2));
    echo 'b';
    return time();
})();
$promise->cancel();
await($promise);
````
This builds on top of reactphp#15, reactphp#18, reactphp#19, reactphp#26, reactphp#28, reactphp#30, and reactphp#32.

Read the original on github.com ↗