<commit_before>import Mixin from '@ember/object/mixin';
import { run } from '@ember/runloop';
import { assert } from '@ember/debug';
import Ember from 'ember';
import getOrAllocate from '../utils/get-or-allocate';

let _shouldPollOverride;
function shouldPoll() {
  if (_shouldPollOverride) {
    return _shouldPollOverride();
  }

  // eslint-disable-next-line ember-suave/no-direct-property-access
  return !Ember.testing;
}

export function setShouldPoll(callback) {
  _shouldPollOverride = callback;
}

let scheduledQueueTasks = Object.create(null);

let queuedPollTasks = Object.create(null);
let pollTaskLabels = Object.create(null);
export function pollTaskFor(label) {
  assert(`A pollTask with a label of '${label}' was not found.`, pollTaskLabels[label]);
  assert(`You cannot advance a pollTask (\`${label}\`) when \`next\` has not been called.`, !!queuedPollTasks[label]);

  return run.join(null, queuedPollTasks[label]);
}

/**
 ContextBoundTasksMixin provides a mechanism to run tasks (ala `setTimeout` or
 `Ember.run.later`) with automatic cancellation when the host object is
 destroyed.

 These capabilities are very commonly needed, so this mixin is by default
 included into all `Ember.View`, `Ember.Component`, and `Ember.Service` instances.

 @class ContextBoundTasksMixin
 @public
 */
export default Mixin.create({
  init() {
    this._super(...arguments);

    this._pendingTimers = undefined;
    this._pendingSchedules = undefined;
    this._pendingDebounces = undefined;
    this._pendingThrottles = undefined;
    this._pollerLabels = undefined;
  },

  /**
   Runs the provided function at the specified timeout (defaulting to 0).
   The timer is properly canceled if the object is destroyed before it is invoked.

   Example:

   ```js
   import Component from 'ember-component';
   import ContextBoundTasksMixin from 'ember-lifeline/mixins/run';
<commit_msg>remove unnecessary property<commit_after>import Mixin from '@ember/object/mixin';
import { run } from '@ember/runloop';
import { assert } from '@ember/debug';
import Ember from 'ember';
import getOrAllocate from '../utils/get-or-allocate';

let _shouldPollOverride;
function shouldPoll() {
  if (_shouldPollOverride) {
    return _shouldPollOverride();
  }

  // eslint-disable-next-line ember-suave/no-direct-property-access
  return !Ember.testing;
}

export function setShouldPoll(callback) {
  _shouldPollOverride = callback;
}

let scheduledQueueTasks = Object.create(null);

let queuedPollTasks = Object.create(null);
let pollTaskLabels = Object.create(null);
export function pollTaskFor(label) {
  assert(`A pollTask with a label of '${label}' was not found.`, pollTaskLabels[label]);
  assert(`You cannot advance a pollTask (\`${label}\`) when \`next\` has not been called.`, !!queuedPollTasks[label]);

  return run.join(null, queuedPollTasks[label]);
}

/**
 ContextBoundTasksMixin provides a mechanism to run tasks (ala `setTimeout` or
 `Ember.run.later`) with automatic cancellation when the host object is
 destroyed.

 These capabilities are very commonly needed, so this mixin is by default
 included into all `Ember.View`, `Ember.Component`, and `Ember.Service` instances.

 @class ContextBoundTasksMixin
 @public
 */
export default Mixin.create({
  init() {
    this._super(...arguments);

    this._pendingTimers = undefined;
    this._pendingDebounces = undefined;
    this._pendingThrottles = undefined;
    this._pollerLabels = undefined;
  },

  /**
   Runs the provided function at the specified timeout (defaulting to 0).
   The timer is properly canceled if the object is destroyed before it is invoked.

   Example:

   ```js
   import Component from 'ember-component';
   import ContextBoundTasksMixin from 'ember-lifeline/mixins/run';

{'fraction_non_alphanumeric': 0.1111407249466951, 'fraction_numerical': 0.0005330490405117271, 'mean_word_length': 4.527245949926362, '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': '3055098', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1080, 'n_words': 340}