<commit_before>import { PullRequestStore } from '../pull-request-store'
import { Account } from '../../../models/account'
import { fatalError } from '../../fatal-error'
import { GitHubRepository } from '../../../models/github-repository'

//** Interval to check for pull requests */
const PullRequestInterval = 1000 * 60 * 10

enum TimeoutHandles {
  PullRequest = 'PullRequestHandle',
  Status = 'StatusHandle',
  PushedPullRequest = 'PushedPullRequestHandle',
}

/**
 * Acts as a service for downloading the latest pull request
 * and status info from GitHub.
 */
export class PullRequestUpdater {
  private readonly timeoutHandles = new Map<TimeoutHandles, number>()
  private isStopped: boolean = true

  public constructor(
    private readonly repository: GitHubRepository,
    private readonly account: Account,
    private readonly store: PullRequestStore
  ) {}

  /** Starts the updater */
  public start() {
    if (!this.isStopped) {
      fatalError(
        'Cannot start the Pull Request Updater that is already running.'
      )

      return
    }

    this.timeoutHandles.set(
      TimeoutHandles.PullRequest,

      window.setTimeout(() => {
        this.store.refreshPullRequests(this.repository, this.account)
      }, PullRequestInterval)
    )
  }

  public stop() {
    this.isStopped = true

    for (const timeoutHandle of this.timeoutHandles.values()) {
      window.clearTimeout(timeoutHandle)
    }

    this.timeoutHandles.clear()
  }
}<commit_msg>Clean up and use setInterval, not setTimeout<commit_after>import { PullRequestStore } from '../pull-request-store'
import { Account } from '../../../models/account'
import { GitHubRepository } from '../../../models/github-repository'

//** Interval to check for pull requests */
const PullRequestInterval = 1000 * 60 * 10

/**
 * Acts as a service for downloading the latest pull request
 * and status info from GitHub.
 */
export class PullRequestUpdater {
  private intervalId: number | null = null

  public constructor(
    private readonly repository: GitHubRepository,
    private readonly account: Account,
    private readonly store: PullRequestStore
  ) {}

  /** Starts the updater */
  public start() {
    this.stop()
    this.intervalId = window.setInterval(() => {
      this.store.refreshPullRequests(this.repository, this.account)
    }, PullRequestInterval)
  }

  public stop() {
    if (this.intervalId !== null) {
      clearInterval(this.intervalId)
      this.intervalId = null
    }
  }
}
{'fraction_non_alphanumeric': 0.11526104417670682, 'fraction_numerical': 0.00642570281124498, 'mean_word_length': 3.214890016920474, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2974085', 'n_tokens_mistral': 707, 'n_tokens_neox': 671, 'n_words': 199}