src/DataLoader.php
public function load($key)
    {
        $this->checkKey($key, __METHOD__);
        // Determine options
        $shouldBatch = $this->options->shouldBatch();
        $shouldCache = $this->options->shouldCache();
        $cacheKey = $this->getCacheKeyFromKey($key);

        // If caching and there is a cache-hit, return cached Promise.
        if ($shouldCache) {
            $cachedPromise = $this->promiseCache->get($cacheKey);
            if ($cachedPromise) {
                return $cachedPromise;
            }
        }

        // Otherwise, produce a new Promise for this value.
        $promise = $this->getPromiseAdapter()->create(
            $resolve,
            $reject,
            function () {
                // Cancel/abort any running operations like network connections, streams etc.

                throw new \RuntimeException('DataLoader destroyed before promise complete.');
            }
        );

        $this->queue[] = [
            'key' => $key,
            'resolve' => $resolve,
            'reject' => $reject,
            'promise' => $promise,
        ];

        // Determine if a dispatch of this queue should be scheduled.
        // A single dispatch should be scheduled per queue at the time when the
        // queue changes from "empty" to "full".
        if (count($this->queue) === 1) {
            if (!$shouldBatch) {
                // Otherwise dispatch the (queue of one) immediately.
                $this->dispatchQueue();
            }
        }
        // If caching, cache this promise.
        if ($shouldCache) {
            $this->promiseCache->set($cacheKey, $promise);
        }

        return $promise;
    }
public function load($key)
    {
        $this->checkKey($key, __METHOD__);
        // Determine options
        $shouldBatch = $this->options->shouldBatch();
        $shouldCache = $this->options->shouldCache();
        $cacheKey = $this->getCacheKeyFromKey($key);

        // If caching and there is a cache-hit, return cached Promise.
        if ($shouldCache) {
            $cachedPromise = $this->promiseCache->get($cacheKey);
            if ($cachedPromise) {
                return $cachedPromise;
            }
        }

        // Otherwise, produce a new Promise for this value.
        $promise = $this->getPromiseAdapter()->create(
            $resolve,
            $reject,
            function () {
                // Cancel/abort any running operations like network connections, streams etc.

                throw new \RuntimeException('DataLoader destroyed before promise complete.');
            }
        );

        $this->queue[] = [
            'key' => $key,
            'resolve' => $resolve,
            'reject' => $reject,
            'promise' => $promise,
        ];

        // Determine if a dispatch of this queue should be scheduled.
        // A single dispatch should be scheduled per queue at the time when the
        // queue changes from "empty" to "full".
        if (count($this->queue) === 1) {
            if (!$shouldBatch) {
                // Otherwise dispatch the (queue of one) immediately.
                $this->dispatchQueue();
            }
        }
        // If caching, cache this promise.
        if ($shouldCache) {
            $this->promiseCache->set($cacheKey, $promise);
        }

        return $promise;
    }
public function load ( $ key ) { $ this -> checkKey ( $ key , __METHOD__ ) ; // Determine options $ shouldBatch = $ this -> options -> shouldBatch ( ) ; $ shouldCache = $ this -> options -> shouldCache ( ) ; $ cacheKey = $ this -> getCacheKeyFromKey ( $ key ) ; // If caching and there is a cache-hit, return cached Promise. if ( $ shouldCache ) { $ cachedPromise = $ this -> promiseCache -> get ( $ cacheKey ) ; if ( $ cachedPromise ) { return $ cachedPromise ; } } // Otherwise, produce a new Promise for this value. $ promise = $ this -> getPromiseAdapter ( ) -> create ( $ resolve , $ reject , function ( ) { // Cancel/abort any running operations like network connections, streams etc. throw new \ RuntimeException ( 'DataLoader destroyed before promise complete.' ) ; } ) ; $ this -> queue [ ] = [ 'key' => $ key , 'resolve' => $ resolve , 'reject' => $ reject , 'promise' => $ promise , ] ; // Determine if a dispatch of this queue should be scheduled. // A single dispatch should be scheduled per queue at the time when the // queue changes from "empty" to "full". if ( count ( $ this -> queue ) === 1 ) { if ( ! $ shouldBatch ) { // Otherwise dispatch the (queue of one) immediately. $ this -> dispatchQueue ( ) ; } } // If caching, cache this promise. if ( $ shouldCache ) { $ this -> promiseCache -> set ( $ cacheKey , $ promise ) ; } return $ promise ; }
{@inheritdoc}
{