<commit_before>/* global assetPath */

const _loaded = {};

function loadWithTag(path, cb) {
  const head = document.getElementsByTagName('head')[0];

  let s = document.createElement('script');
  s.src = path;
  if (Ember.Test) { Ember.Test.pendingAjaxRequests++; }
  head.appendChild(s);

  s.onload = s.onreadystatechange = function(_, abort) {
    if (Ember.Test) { Ember.Test.pendingAjaxRequests--; }
    if (abort || !s.readyState || s.readyState === "loaded" || s.readyState === "complete") {
      s = s.onload = s.onreadystatechange = null;
      if (!abort) {
        Ember.run(null, cb);
      }
    }
  };
}

export default function loadScript(url, opts) {
  opts = opts || {};

  return new Ember.RSVP.Promise(function(resolve) {
    url = Discourse.getURL((assetPath && assetPath(url)) || url);

    // If we already loaded this url
    if (_loaded[url]) { return resolve(); }

    const cb = function() {
      _loaded[url] = true;<commit_msg>FIX: guard against concurrent loading of deferred assets<commit_after>/* global assetPath */

const _loaded = {};
const _loading = {};

function loadWithTag(path, cb) {
  const head = document.getElementsByTagName('head')[0];

  let s = document.createElement('script');
  s.src = path;
  if (Ember.Test) { Ember.Test.pendingAjaxRequests++; }
  head.appendChild(s);

  s.onload = s.onreadystatechange = function(_, abort) {
    if (Ember.Test) { Ember.Test.pendingAjaxRequests--; }
    if (abort || !s.readyState || s.readyState === "loaded" || s.readyState === "complete") {
      s = s.onload = s.onreadystatechange = null;
      if (!abort) {
        Ember.run(null, cb);
      }
    }
  };
}

export default function loadScript(url, opts) {
  opts = opts || {};

  return new Ember.RSVP.Promise(function(resolve) {
    url = Discourse.getURL((assetPath && assetPath(url)) || url);

    // If we already loaded this url
    if (_loaded[url]) { return resolve(); }
    if (_loading[url]) { return _loading[url].then(resolve);}

    var done;
    _loading[url] = new Ember.RSVP.Promise(function(_done){
      done = _done;
    });

    _loading[url].then(function(){
      delete _loading[url];
    });

    const cb = function() {
      _loaded[url] = true;
      done();
{'fraction_non_alphanumeric': 0.1622590766472434, 'fraction_numerical': 0.0008964589870013447, 'mean_word_length': 3.211320754716981, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1213411', 'n_tokens_mistral': 743, 'n_tokens_neox': 731, 'n_words': 165}