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

Make the promise interface a generic in phpDoc #163

Open
apokryfos opened this issue Oct 2, 2023 · 0 comments
Open

Make the promise interface a generic in phpDoc #163

apokryfos opened this issue Oct 2, 2023 · 0 comments

Comments

@apokryfos
Copy link

Description
Can we add generic phpDoc blocks for promises?

Example
For example in the promise interface:

<?php

namespace GuzzleHttp\Promise;

/**
 * @template T
 */
interface PromiseInterface
{
   // ...  

   /**
     * @param callable(): T $onFulfilled Invoked when the promise fulfills.
     * @param callable $onRejected  Invoked when the promise is rejected.
     * @return PromiseInterface<T>
     */
    public function then(
        callable $onFulfilled = null,
        callable $onRejected = null
    );

    //...
    /**
     * Resolve the promise with the given value.
     *
     * @param T $value
     *
     * @throws \RuntimeException if the promise is already resolved.
     */
    public function resolve($value);

    /**
     * Waits until the promise completes if possible.
     *
     * Pass $unwrap as true to unwrap the result of the promise, either
     * returning the resolved value or throwing the rejected exception.
     *
     * If the promise cannot be waited on, then the promise will be rejected.
     *
     * @param bool $unwrap
     *
     * @return ($unwrap is true ? T : PromiseInterface)
     *
     * @throws \LogicException if the promise has no wait function or if the
     *                         promise does not settle after waiting.
     */
    public function wait($unwrap = true);
}

I imagine the rest of the classes need to have their docblocks updated to reflect this.

Additional context

I can help to implement this but I'm not too confident on the code base to do it alone.

Let me know what you think of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant