Skip to content

Make the promise interface a generic in phpDoc #163

@apokryfos

Description

@apokryfos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions