<commit_before>import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

import { Observable, Subject } from 'rxjs';
import { map } from 'rxjs/operators';

import Folder from '../folder';
import Device from '../device';
import { environment } from '../../environments/environment'
import { apiURL } from '../api-utils'
import { ProgressService } from './progress.service';

@Injectable({
  providedIn: 'root'
})
export class SystemConfigService {
  private folders: Folder[];
  private devices: Device[];
  private foldersSubject: Subject<Folder[]> = new Subject();
  private devicesSubject: Subject<Device[]> = new Subject();

  private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config';

  private checkInterval: number = 100;

  constructor(
    private http: HttpClient,
    private progressService: ProgressService,
  ) { }

  getSystemConfig(): Observable<any> {
    return this.http
      .get(this.systemConfigUrl)
      .pipe(
        map(res => {
          this.folders = res['folders'];
          this.devices = res['devices'];

          // Set the total for the progress service
          this.progressService.total = this.folders.length + this.devices.length;

          this.foldersSubject.next(this.folders);
          this.devicesSubject.next(this.devices);

          return res;
        })
      );
  }

  getFolders(): Observable<Folder[]> {
    const folderObservable: Observable<Folder[]> = new Observable((observer) => {
      if (this.folders) {
        observer.next(this.folders);
        observer.complete();
      } else {
        // create timer to keep checking for folders
        let t = setInterval(() => {
          if (this.folders) {
            clearInterval(t);
            observer.next(this.folders)
            observer.complete();
          }
        }, this.checkInterval);
      }
    });
    return folderObservable;
  }

  getDevices(): Observable<Device[]> {
    const deviceObserverable: Observable<Device[]> = new Observable((observer) => {
      if (this.devices) {
        observer.next(this.devices);
      } else {
        let t = setInterval(() => {
          if (this.devices) {
            clearInterval(t);
            observer.next(this.devices);
          }
        }, this.checkInterval);
      }
    });
    return deviceObserverable;
  }
}<commit_msg>use replay subject in place of timer<commit_after>import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Observable, ReplaySubject } from 'rxjs';
import { map } from 'rxjs/operators';

import Folder from '../folder';
import Device from '../device';
import { environment } from '../../environments/environment'
import { apiURL } from '../api-utils'
import { ProgressService } from './progress.service';

@Injectable({
  providedIn: 'root'
})
export class SystemConfigService {
  private folders: Folder[];
  private devices: Device[];
  private foldersSubject: ReplaySubject<Folder[]> = new ReplaySubject(1);
  private devicesSubject: ReplaySubject<Device[]> = new ReplaySubject(1);

  private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config';

  constructor(
    private http: HttpClient,
    private progressService: ProgressService,
  ) { }

  getSystemConfig(): Observable<any> {
    return this.http
      .get(this.systemConfigUrl)
      .pipe(
        map(res => {
          this.folders = res['folders'];
          this.devices = res['devices'];

          // Set the total for the progress service
          this.progressService.total = this.folders.length + this.devices.length;

          this.foldersSubject.next(this.folders);
          this.devicesSubject.next(this.devices);

          return res;
        })
      );
  }

  getFolders(): Observable<Folder[]> {
    return this.foldersSubject.asObservable();
  }

  getDevices(): Observable<Device[]> {
    return this.devicesSubject.asObservable();
  }
}
{'fraction_non_alphanumeric': 0.1339152119700748, 'fraction_numerical': 0.0012468827930174563, 'mean_word_length': 2.8641618497109826, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '2260812', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1103, 'n_words': 264}