Skip to content

Promise not working as async without wait() #89

@zelin

Description

@zelin

The code works if i do $promise->wait();, however i am not sure how can i call the promise to work async.

foreach ($entries as $key=>$value)
        {     
                $promise = new Promise(function() use (&$promise, $key, $value) 
                {   
                    // Do some heavy lifting work.
                    $mainOutput = array($key, $output, $value);
                    $promise->resolve($mainOutput);
                });

                $promise->then(
                    // $onFulfilled
                    function ($mainOutput)
                    {
                        static::addToResponse($mainOutput);
                    },
                    // $onRejected
                    function ($reason) 
                    {
                        echo 'The promise was rejected.';
                    }
                );
            if(static::$sync)  
            {    
                $promise->wait();
            }
            else
            {

            }
        }

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