mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-28 04:55:53 +00:00
use replay subject in place of timer
This commit is contained in:
parent
3fbc51cd38
commit
f53475a204
@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
|
||||||
import { Observable, Subject } from 'rxjs';
|
import { Observable, ReplaySubject } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
import Folder from '../folder';
|
import Folder from '../folder';
|
||||||
@ -16,13 +16,11 @@ import { ProgressService } from './progress.service';
|
|||||||
export class SystemConfigService {
|
export class SystemConfigService {
|
||||||
private folders: Folder[];
|
private folders: Folder[];
|
||||||
private devices: Device[];
|
private devices: Device[];
|
||||||
private foldersSubject: Subject<Folder[]> = new Subject();
|
private foldersSubject: ReplaySubject<Folder[]> = new ReplaySubject(1);
|
||||||
private devicesSubject: Subject<Device[]> = new Subject();
|
private devicesSubject: ReplaySubject<Device[]> = new ReplaySubject(1);
|
||||||
|
|
||||||
private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config';
|
private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config';
|
||||||
|
|
||||||
private checkInterval: number = 100;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
private progressService: ProgressService,
|
private progressService: ProgressService,
|
||||||
@ -48,37 +46,10 @@ export class SystemConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getFolders(): Observable<Folder[]> {
|
getFolders(): Observable<Folder[]> {
|
||||||
const folderObservable: Observable<Folder[]> = new Observable((observer) => {
|
return this.foldersSubject.asObservable();
|
||||||
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[]> {
|
getDevices(): Observable<Device[]> {
|
||||||
const deviceObserverable: Observable<Device[]> = new Observable((observer) => {
|
return this.devicesSubject.asObservable();
|
||||||
if (this.devices) {
|
|
||||||
observer.next(this.devices);
|
|
||||||
} else {
|
|
||||||
let t = setInterval(() => {
|
|
||||||
if (this.devices) {
|
|
||||||
clearInterval(t);
|
|
||||||
observer.next(this.devices);
|
|
||||||
}
|
|
||||||
}, this.checkInterval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return deviceObserverable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user