<commit_before>'use strict';

// turns a function that resolves with a page of items into a generator-powered iterator
// pageFn: function that may be called to retrieve the next page of data
function* pageToGenerator(pageFn) {
    let nextPageExists = true;
    let bank = [];
    let fetchPromise = Promise.resolve();
    while (bank.length > 0 || nextPageExists) {
        if (bank.length > 0) {
            yield Promise.resolve(bank.shift());
        } else {
            fetchPromise = fetchPromise.then(pageFn).then(function(response) {
                nextPageExists = !!response.pages.next;
                bank = response.data;

                return bank.shift();
            });

            yield fetchPromise;
        }
    }
}

module.exports = pageToGenerator;<commit_msg>page-to-generator funciton fixes<commit_after>'use strict';

// turns a function that resolves with a page of items into a generator-powered iterator
// pageFn: function that may be called to retrieve the next page of data
function* pageToGenerator(pageFn) {
    let nextPageExists = true;
    let bank = [];
    let fetchPromise = Promise.resolve();
    while (bank.length > 0 || nextPageExists) {

        fetchPromise = fetchPromise.then(function() {
            if (bank.length === 0) {
                return pageFn().then(function(response) {
                    nextPageExists = !!response.pages.next;
                    bank = response.data;

                    return bank.shift();
                });
            }

            return bank.shift();
        });

        yield fetchPromise;
    }
}

module.exports = pageToGenerator;
{'fraction_non_alphanumeric': 0.10165339865278629, 'fraction_numerical': 0.002449479485609308, 'mean_word_length': 2.1005692599620494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6788004', 'n_tokens_mistral': 430, 'n_tokens_neox': 409, 'n_words': 124}