1234567891011121314151617181920212223242526272829303132333435363738 |
- import { from, map, Observable, of, Subject } from "rxjs";
- import * as fs from "fs"
- import { BaseMessage } from "../dependencies/fisloggingservice/services/logging-service";
- export class StreamingService {
- private messagesJSON: any = fs.readFileSync("testRequest.json")
- private messages = JSON.parse(this.messagesJSON)
- // public stream(): Observable<BaseMessage> {
- // return new Observable(subject => {
- // let messages = this.messages
- // let count = 0
- // const intervalId = setInterval(() => {
- // subject.next(messages[count]);
- // count++;
- // if (count >= 4) {
- // clearInterval(intervalId);
- // subject.complete();
- // }
- // }, 1000)
- // })
- // }
- public stream(): Subject<BaseMessage> {
- let result: Subject<BaseMessage> = new Subject()
- let messages = this.messages
- let count = 0
- const intervalId = setInterval(() => {
- result.next(messages[count]);
- count++;
- if (count >= 4) {
- clearInterval(intervalId);
- result.complete();
- }
- }, 1000)
- return result
- }
- }
|