<commit_before>'use strict';

module.exports = (NODE) => {
  let used = false;
  let refreshing = false;
  let values;

  const refreshIn = NODE.getInputByName('refresh');
  const valueIn = NODE.getInputByName('value');

  const refreshOut = NODE.getOutputByName('refreshed');
  const valueOut = NODE.getOutputByName('value');

  refreshIn.on('trigger', (conn, state) => {
    // get the input values
    refreshing = true;
    valueIn.getValues(state).then((vals) => {
      used = true;
      refreshing = false;
      values = vals;

      // save the state
      state.set(NODE, {
        values: vals
      });

      refreshOut.trigger(state);
    });
  });

  valueOut.on('trigger', async (conn, state) => {
    // state handling (if refresh complete was used)
    const thisState = state.get(NODE);
    if (thisState) {
      return thisState.values;
    }

    // callback immeditialy if we already have this value(s) in store
    if (used) {
      return values;
    }

    // wait to callback when we're currently refreshing the value(s)
    if (refreshing) {
      return new Promise((resolve) => {
        valueOut.once('triggerdone', () => {
          resolve(values);
        });
      });
    }

    // perform a refresh of all inputs and return those values
    refreshing = true;
    values = await valueIn.getValues(state);
    used = true;
    refreshing = false;

    return values;
  });
};<commit_msg>replace triggerdone by custom refresh event<commit_after>'use strict';

module.exports = (NODE) => {
  let used = false;
  let refreshing = false;
  let values;

  const refreshIn = NODE.getInputByName('refresh');
  const valueIn = NODE.getInputByName('value');

  const refreshOut = NODE.getOutputByName('refreshed');
  const valueOut = NODE.getOutputByName('value');

  refreshIn.on('trigger', (conn, state) => {
    // get the input values
    refreshing = true;
    valueIn.getValues(state).then((vals) => {
      used = true;
      refreshing = false;
      values = vals;

      // save the state
      state.set(NODE, {
        values: vals
      });

      refreshOut.trigger(state);
    });
  });

  valueOut.on('trigger', async (conn, state) => {
    // state handling (if refresh complete was used)
    const thisState = state.get(NODE);
    if (thisState) {
      return thisState.values;
    }

    // callback immeditialy if we already have this value(s) in store
    if (used) {
      return values;
    }

    // wait to callback when we're currently refreshing the value(s)
    if (refreshing) {
      return new Promise((resolve) => {
        NODE.once('refreshed', () => {
          resolve(values);
        });
      });
    }

    // perform a refresh of all inputs and return those values
    refreshing = true;
    values = await valueIn.getValues(state);
    used = true;
    refreshing = false;

    NODE.emit('refreshed');

    return values;
  });
};
{'fraction_non_alphanumeric': 0.12961047914512236, 'fraction_numerical': 0.0, 'mean_word_length': 2.5347137637028014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4852180', 'n_tokens_mistral': 890, 'n_tokens_neox': 876, 'n_words': 238}