/*
Yield all results from the API
19895
public function getResultGenerator($entity, $filters = [])
    {
        $methodName = 'get' . ucfirst($entity) . 's';

        $i = 0;
        $gotAll = false;
        while ($gotAll === false) {
            $filters['offset'] = ($i * 100);

            $result = $this->$methodName($filters);
            if (! isset($result['success']) || ! isset($result['data']) || $result['success'] !== true) {
                throw new Exception("Invalid API response: " . json_encode($result));
            }

            if (count($result['data']) < 100) {
                $gotAll = true;
            }

            foreach ($result['data'] as $item) {
                yield $item;
            }

            $i++;
        }
    }
661182
function gotResults(results) {
  results.JSONquery = JSON.stringify(results.query, null, 2);
  console.log('gotResults', results);
  updateResults(results);
}
1290363
function resultsCallback() {
    
    var args = slice.call(arguments, 0);
    var err = args.shift();
        
    if (err) {
      if (config.interrupt === true) {
        errors.push(err);
        results.push(null);
        callback.call(self, errors, results);
        return;
      } else {
         errored = true; 
         args = null;
      }
    } else if (args.length === 0) {
      args = 'OK';
    } else if (args.length == 1) {
      args = args[0];
    }
    
    errors.push(err);
    results.push(args);
    
    self.emit('each', err, counter, args);
    
    if (config.parallel) {
      
      // Parallel

      if (++counter == stack.length) {
        self.promise.emit('finished');
      }

    } else {
      
      // Sequential
      
      if (++counter == stack.length) {
        var preparedArgs = setInitialState(true); // Reset state, then return
        self.emit('post_exec');
        callback.apply(self, preparedArgs);
      } else {
        var next = stack[counter];
        context[next.caller].apply(context, next.args);
      }

    }

  }
670934
@NotNull
	public static Promise<Void> all(@NotNull Iterator<? extends Promise<?>> promises) {
		if (!promises.hasNext()) return all();
		@NotNull PromiseAll<Object> resultPromise = new PromiseAll<>();
		while (promises.hasNext()) {
			Promise<?> promise = promises.next();
			if (promise.isResult()) continue;
			if (promise.isException()) return Promise.ofException(promise.materialize().getException());
			resultPromise.countdown++;
			promise.next(resultPromise);
		}
		return resultPromise.countdown != 0 ? resultPromise : Promise.complete();
	}
1040454
def each(io)
      if block_given?
        filter = BELParser::ASTFilter.new(
          BELParser::ASTGenerator.new(io),
          *TYPES)
        filter.each do |results|
          yield results
        end
      else
        enum_for(:each, io)
      end
    end
938471
private void returnResults() {
    final StringBuilder sb = new StringBuilder();
    for (final String result : this.results) {
      sb.append(result);
    }
    this.results.clear();
    LOG.log(Level.INFO, "Return results to the client:\n{0}", sb);
    httpCallbackHandler.onNext(CODEC.encode(sb.toString()));
  }
1183958
function (source, callback, context) {
            var results = [];
            var i = source.length;
            while (i--) {
                results[i] = callback.call(context || source, source[i], i);
            }
            return results;
        }
533728
function result () {
    // wait for all queries to complete then build result
    return this.promise.then(results => {
        // if the entire result set is a cached view then skip processing
        if (results._cachedView) {
            // result is from collection view
            if (this.modelViewEngine.hasCollection) {
                return results
            }
            // result is record(s)
            else {
                return this.resultRaw(results)
            }
        }
        // order results if needed
        if (results.length > 1) {
            results = this.orderResults(results)
        }
        // if there are model views then build result with ModelViewEngine
        // otherwise build result based on raw data
        return defined(this.modelViewEngine)
            ? this.resultModelView(results)
            : this.resultRaw(results)
    })
}
240783
def iterator(self):
        
        if not self._result_cache:
            len(self)
        for r in self._result_cache:
            yield r
1119353
def each
      @data.each do |section, hash|
        hash.each do |key, value|
          yield [section, key, value]
        end
      end
    end
722929
def _get_results(FetcherClass, services, kwargs, num_results=None, fast=0, verbose=False, timeout=None):
    
    results = []

    if not num_results or fast:
        num_results = len(services)

    with futures.ThreadPoolExecutor(max_workers=len(services)) as executor:
        fetches = {}
        for service in services[:num_results]:
            tail = [x for x in services if x is not service]
            random.shuffle(tail)
            srv = FetcherClass(services=[service] + tail, verbose=verbose, timeout=timeout)
            fetches[executor.submit(srv.action, **kwargs)] = srv

        if fast == 1:
            raise NotImplementedError
            # ths code is a work in progress. futures.FIRST_COMPLETED works differently than I thought...
            to_iterate, still_going = futures.wait(fetches, return_when=futures.FIRST_COMPLETED)
            for x in still_going:
                try:
                    x.result(timeout=1.001)
                except futures._base.TimeoutError:
                    pass

        elif fast > 1:
            raise Exception("fast level greater than 1 not yet implemented")
        else:
            to_iterate = futures.as_completed(fetches)

        for future in to_iterate:
            service = fetches[future]
            results.append([service, future.result()])

    return results
734072
def all(self):
        
        page = self._load(self.href)
        while True:
            try:
                for item in page._items:
                    yield item
                page = page.next_page()
            except PaginationError:
                break
918907
function all (promises) {

    var done      = new promise.Promise,
        successes = [],
        failures  = [],
        failed    = false,
        completed = 0,
        total     = promises.length;

    if (promises.length === 0) {
        done.resolve([]);
        return done;
    }

    var check = function () {
        if (++completed < total) {
            return;
        }
        if (failures.length) {
            failures.successes = successes;
            done.reject(failures);
        }
        else {
            done.resolve(successes);
        }
    };

    for (var i = 0; i < total; i++) {
        promise.when(promises[i], function (result) {
            successes[i] = result;
            check();
        }, function (error) {
            failures[i] = error;
            check();
        });
    }

    return done;
}
1337465
function scrapeAll(query, scrapeDetails) {

    return co(function *() {
        //By default, scrape the card details
        scrapeDetails = scrapeDetails === undefined ? true : scrapeDetails;

        //Load the HTML page
        const scrapeURL = makeUrl(SCRAPE_URL, query);
        const search = yield scrapeSearchPage(scrapeURL);

        //Recurring variables
        var cards = search.cards;
        var i;

        //Scrape all of the pages sequentially;
        for (i = 2; i <= search.numPages; i++) {
            const scrapeURL = makeUrl(Url.resolve(SCRAPE_URL, i.toString()), query);
            const results = yield scrapeSearchPage(scrapeURL);
            cards = cards.concat(results.cards);
        }

        //Scrape all of the cards sequentially if requested
        if (scrapeDetails) {
            for (i = 0; i < cards.length; i++) {
                const card = cards[i];
                _.assign(card, yield scrapeCard(card.url));
            }
        }

        return cards;
    })();
}
101564
def get_all_results(starting_page):
    
    logging.info('Retrieving all results for {}'.format(starting_page))
    page = starting_page
    results = []

    while True:
        logging.debug('Getting data from: {}'.format(page))
        data = get_page(page)
        logging.debug('JSON data: {}'.format(data))
        results = results + data['results']

        if data['next']:
            page = data['next']
        else:
            break

    return results
352950
function() {
      var privateCollection = this.privateCollection;
      if (!this.parentBehavior.returnSingleResult) {
        return privateCollection.toJSON();
      }

      if (privateCollection.length === 0) {
        return undefined;
      } else if (privateCollection.length === 1) {
        var singleResultModel = privateCollection.at(0);
        return singleResultModel.toJSON();
      } else {
        throw new Error('Multiple results found, but single result expected: ' + JSON.stringify(privateCollection.toJSON()));
      }
    }
392820
def results(self, *args, **kwargs):
        
        def worker():
            kwargs['page'] = 1
            while True:
                response = self.client(*args, **kwargs)
                if isinstance(response, list):
                    yield response
                    break
                elif _is_page(response):
                    yield response['results']
                    if response['next']:
                        kwargs['page'] += 1
                    else:
                        break
                else:
                    raise NoResultsError(response)

        return itertools.chain.from_iterable(worker())