<commit_before>import Ember from 'ember';
import config from '../config/environment';
import { task, timeout } from 'ember-concurrency';

const EMBER_VERSIONS = ['2.6.0', '2.5.1', '2.4.5', '2.3.2', '2.2.2', '2.1.2', '2.0.3', '1.13.13', '1.12.2'];
const EMBER_DATA_VERSIONS = ['2.6.1', '2.5.3', '2.4.3', '2.3.3', '2.2.1', '2.1.0', '2.0.1', '1.13.15'];

const VERSION_REGEX = /^\d+.\d+.\d+(-beta\.\d+)?$/;

const CDN_MAP = {
  'ember': {
    library: 'ember.js',
    fileName: 'ember.debug.js'
  },

  'ember-template-compiler': {
    library: 'ember.js',
    fileName: 'ember-template-compiler.js'
  },

  'ember-data': {
    library: 'ember-data.js',
    fileName: 'ember-data.js'
  }
};

const CHANNEL_FILENAME_MAP = {
  'ember': 'ember.debug.js',
  'ember-template-compiler': 'ember-template-compiler.js',
  'ember-data': 'ember-data.js'
};

const CHANNELS = ['canary', 'beta', 'release'];

const { computed, RSVP } = Ember;

export default Ember.Service.extend({
  resolveDependencies: function(dependencies) {
    Object.keys(dependencies).forEach((name) => {
      var value = dependencies[name];

      dependencies[name] = this.resolveDependency(name, value);
    });
  },

  resolveAddons: function(addons, dependencies) {
    const taskInstance = this.get('resolveAddonsTask').perform(addons, dependencies);
    return taskInstance.then(() => {
      return RSVP.resolve(taskInstance.value);
    });
  },

  resolveAddonsTask: task(function *(addons, dependencies) {
    let done = false;
    while (!done) {
      let addonPromises = {};
      let addonNames = Object.keys(addons);
      for (let i = 0; i < addonNames.length; ++i) {
        const name = addonNames[i];
        const value = addons[name];
        addonPromises[name] = this.resolveAddon(name, value);
      }
      let hash = yield RSVP.hash(addonPromises);
      let allAddonsLoaded = true;
      for (let j = 0; j < addonNames.length; ++j) {
        const name = addonNames[j];
        const addon = hash[name];
        if (addon.status === 'build_success') {
          dependencies[name] = addon.addon_js;
          dependencies[name+'_css'] = addon.addon_css;
          console.log(`Addon ${name} is loaded...`);
          delete addons[name];
        } else if (addon.status === 'building') {
          console.log(`Addon ${name} is still building...`);
          allAddonsLoaded = false;
        } else if (addon.status === 'build_error') {
          console.error(`Addon ${name} encountered a build error:`);
          console.error(addon.errors, addon.ember_errors);
          allAddonsLoaded = false;
          throw addon;
        }
      }
      if (allAddonsLoaded) {
        done = true;
      } else {
        yield timeout(1000);
      }
    }
    return dependencies;
  }),

  resolveAddon(name, value) {
    return new RSVP.Promise(function(resolve) {
      const url = `${config.addonUrl}?ember_version=1.13.15&addon=${name}&addon_version=${value}`;
      resolve(Ember.$.getJSON(url).then(data => RSVP.resolve(data)));
    });
  },<commit_msg>Adjust Polling Interval to save 2333<commit_after>import Ember from 'ember';
import config from '../config/environment';
import { task, timeout } from 'ember-concurrency';

const EMBER_VERSIONS = ['2.6.0', '2.5.1', '2.4.5', '2.3.2', '2.2.2', '2.1.2', '2.0.3', '1.13.13', '1.12.2'];
const EMBER_DATA_VERSIONS = ['2.6.1', '2.5.3', '2.4.3', '2.3.3', '2.2.1', '2.1.0', '2.0.1', '1.13.15'];

const VERSION_REGEX = /^\d+.\d+.\d+(-beta\.\d+)?$/;

const CDN_MAP = {
  'ember': {
    library: 'ember.js',
    fileName: 'ember.debug.js'
  },

  'ember-template-compiler': {
    library: 'ember.js',
    fileName: 'ember-template-compiler.js'
  },

  'ember-data': {
    library: 'ember-data.js',
    fileName: 'ember-data.js'
  }
};

const CHANNEL_FILENAME_MAP = {
  'ember': 'ember.debug.js',
  'ember-template-compiler': 'ember-template-compiler.js',
  'ember-data': 'ember-data.js'
};

const CHANNELS = ['canary', 'beta', 'release'];

const POLL_INTERVAL = 10000;

const { computed, RSVP } = Ember;

export default Ember.Service.extend({
  resolveDependencies: function(dependencies) {
    Object.keys(dependencies).forEach((name) => {
      var value = dependencies[name];

      dependencies[name] = this.resolveDependency(name, value);
    });
  },

  resolveAddons: function(addons, dependencies) {
    const taskInstance = this.get('resolveAddonsTask').perform(addons, dependencies);
    return taskInstance.then(() => {
      return RSVP.resolve(taskInstance.value);
    });
  },

  resolveAddonsTask: task(function *(addons, dependencies) {
    let done = false;
    while (!done) {
      let addonPromises = {};
      let addonNames = Object.keys(addons);
      for (let i = 0; i < addonNames.length; ++i) {
        const name = addonNames[i];
        const value = addons[name];
        addonPromises[name] = this.resolveAddon(name, value);
      }
      let hash = yield RSVP.hash(addonPromises);
      let allAddonsLoaded = true;
      for (let j = 0; j < addonNames.length; ++j) {
        const name = addonNames[j];
        const addon = hash[name];
        if (addon.status === 'build_success') {
          dependencies[name] = addon.addon_js;
          dependencies[name+'_css'] = addon.addon_css;
          console.log(`Addon ${name} is loaded...`);
          delete addons[name];
        } else if (addon.status === 'building') {
          console.log(`Addon ${name} is still building...`);
          allAddonsLoaded = false;
        } else if (addon.status === 'build_error') {
          console.error(`Addon ${name} encountered a build error:`);
          console.error(addon.errors, addon.ember_errors);
          allAddonsLoaded = false;
          throw addon;
        }
      }
      if (allAddonsLoaded) {
        done = true;
      } else {
        yield timeout(POLL_INTERVAL);
      }
    }
    return dependencies;
  }),

  resolveAddon(name, value) {
    return new RSVP.Promise(function(resolve) {
      const url = `${config.addonUrl}?ember_version=1.13.15&addon=${name}&addon_version=${value}`;
      resolve(Ember.$.getJSON(url).then(data => RSVP.resolve(data)));
    });
  },
{'fraction_non_alphanumeric': 0.1762214983713355, 'fraction_numerical': 0.02263843648208469, 'mean_word_length': 2.8309419837804115, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5918465', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2111, 'n_words': 414}