<commit_before>// tslint:disable no-default-export

export default function createTaskWithTimeout(
  task: () => Promise<any>,
  id: string,
  options: { timeout?: number } = {}
) {
  const timeout = options.timeout || 1000 * 60 * 2; // two minutes

  const errorForStack = new Error('for stack');

  return async () =>
    new Promise((resolve, reject) => {
      let complete = false;
      let timer: any = setTimeout(() => {
        if (!complete) {
          const message = `${id ||
            ''} task did not complete in time. Calling stack: ${
            errorForStack.stack
          }`;

          window.log.error(message);
          reject(new Error(message));

          return;
        }

        return null;
      }, timeout);
      const clearTimer = () => {
        try {
          const localTimer = timer;
          if (localTimer) {
            timer = null;
            clearTimeout(localTimer);
          }
        } catch (error) {
          window.log.error(
            id || '',
            'task ran into problem canceling timer. Calling stack:',
            errorForStack.stack
          );
        }
      };

      const success = (result: any) => {
        clearTimer();
        complete = true;
        resolve(result);

        return;
      };
      const failure = (error: Error) => {
        clearTimer();
        complete = true;
        reject(error);

        return;
      };
<commit_msg>Minor: remove `any`s from `createTaskWithTimeout`<commit_after>// tslint:disable no-default-export

export default function createTaskWithTimeout<T>(
  task: () => Promise<T>,
  id: string,
  options: { timeout?: number } = {}
): () => Promise<T> {
  const timeout = options.timeout || 1000 * 60 * 2; // two minutes

  const errorForStack = new Error('for stack');

  return async () =>
    new Promise((resolve, reject) => {
      let complete = false;
      let timer: NodeJS.Timeout | null = setTimeout(() => {
        if (!complete) {
          const message = `${id ||
            ''} task did not complete in time. Calling stack: ${
            errorForStack.stack
          }`;

          window.log.error(message);
          reject(new Error(message));

          return;
        }

        return null;
      }, timeout);
      const clearTimer = () => {
        try {
          const localTimer = timer;
          if (localTimer) {
            timer = null;
            clearTimeout(localTimer);
          }
        } catch (error) {
          window.log.error(
            id || '',
            'task ran into problem canceling timer. Calling stack:',
            errorForStack.stack
          );
        }
      };

      const success = (result: T) => {
        clearTimer();
        complete = true;
        resolve(result);

        return;
      };
      const failure = (error: Error) => {
        clearTimer();
        complete = true;
        reject(error);

        return;
      };

{'fraction_non_alphanumeric': 0.12810902896081772, 'fraction_numerical': 0.004770017035775128, 'mean_word_length': 1.6522131887985547, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 22, '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': '906943', 'n_tokens_mistral': 810, 'n_tokens_neox': 783, 'n_words': 210}