Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fiber-based async and await functions #15

Merged
merged 3 commits into from
Nov 22, 2021

Conversation

WyriHaximus
Copy link
Member

This changeset adds an await function which starts a fiber. And also changes the await function to use fibers introduced in PHP 8.1 instead of continuously running the event loop until the promise resolves and then stopping the event loop. Accordingly, this is a breaking change that will target the future v4 release. The future v3 and v2 releases are still outstanding and are not affected by this change.

These functions are inspired by @trowski's https://github.com/trowski/react-fiber.

Builds on top of #14

clue and others added 2 commits November 22, 2021 15:18
While there is no technical need to add this for this, we also don't want to block other projects creating adapters. However, this interoperability support is undocumented and as such unsupported. Use at your own risk.
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awwwesome! 🎉 We've been working towards this for months, time to finally get this shipped! :shipit:

@clue clue merged commit 80aa19f into reactphp:main Nov 22, 2021
kelunik added a commit to revoltphp/event-loop that referenced this pull request Nov 22, 2021
This is equivalent to the interface change in reactphp/async#15 to allow different implementations.

This also allows decorating `Suspension` to implement listeners like proposed in #2.
kelunik added a commit to revoltphp/event-loop that referenced this pull request Nov 22, 2021
This is equivalent to the interface change in reactphp/async#15 to allow different implementations.

This also allows decorating `Suspension` to implement listeners like proposed in #2.
kelunik added a commit to revoltphp/event-loop that referenced this pull request Nov 22, 2021
This is equivalent to the interface change in reactphp/async#15 to allow different implementations.

This also allows decorating `Suspension` to implement listeners like proposed in #2.
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants