test-streamOBS.ts 886 B

1234567891011121314151617181920212223242526
  1. /* ---------------------- Simulate a stream of messages to be inserted or used by the test ---------------------- */
  2. import { from, map, Observable, of, Subject } from "rxjs";
  3. import * as fs from "fs"
  4. import { BaseMessage } from "../dependencies/log/services/logging-service";
  5. export class StreamingService {
  6. private messagesJSON: any = fs.readFileSync("testRequest.json")
  7. private messages = JSON.parse(this.messagesJSON)
  8. public stream(): Subject<BaseMessage> {
  9. let result: Subject<BaseMessage> = new Subject()
  10. let messages = this.messages
  11. let count = 0
  12. const intervalId = setInterval(() => {
  13. result.next(messages[count]);
  14. count++;
  15. if (count >= 5) {
  16. clearInterval(intervalId);
  17. result.complete();
  18. }
  19. }, 1000)
  20. return result
  21. }
  22. }