test-streamOBS.ts 711 B

12345678910111213141516171819202122
  1. import { from, map, Observable, of } from "rxjs";
  2. import * as fs from "fs"
  3. export class StreamingService {
  4. private messagesJSON: any = fs.readFileSync("dependencies/fisloggingservice/messages.json")
  5. private messages = JSON.parse(this.messagesJSON)
  6. public stream(): Observable<any> {
  7. return new Observable(observer => {
  8. let messages = this.messages
  9. let count = 0
  10. const intervalId = setInterval(() => {
  11. observer.next(messages[count]);
  12. count++;
  13. if (count >= 7) {
  14. clearInterval(intervalId);
  15. observer.complete();
  16. }
  17. }, 1000)
  18. })
  19. }
  20. }