123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { interval, Observable, Subject, Subscription } from "rxjs"
- import { FisCreateMessageUtility } from "../../dependencies/logging/dependencies/msgutil/services/fis.create.message"
- import { BaseMessage } from "../../dependencies/logging/services/logging-service"
- let messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
- export function prepareResponseMessages(amount: number, intervalBetweenMessages?: number): Subject<BaseMessage> {
- let responseData: any[] = []
- let returnSubject = new Subject<BaseMessage>()
- for (let i = 0; i < 1000; i++) {
- responseData.push(`bla bla bla`)
- }
- let count = 0
- let subscription: Subscription
- if (intervalBetweenMessages) {
- // console.log(`Generate data with intervals`)
- subscription = interval(intervalBetweenMessages).subscribe({ // 10millisecond
- next: () => {
- count++
- if (count <= amount) {
- let message = messageUtil.getResponseDataMessage('123', responseData, messageUtil.getLoginMessage())
- returnSubject.next(message)
- } else {
- returnSubject.complete()
- subscription.unsubscribe()
- }
- }
- });
- } else {
- // console.log(`Generate data without intervals`)
- for (let i = 0; i <= amount; i++) {
- if (i >= amount) {
- returnSubject.complete()
- } else {
- let message = messageUtil.getResponseDataMessage('123', responseData, messageUtil.getLoginMessage())
- returnSubject.next(message)
- }
- }
- }
- return returnSubject
- }
- export function generateSingleMessage() {
- return messageUtil.getResponseDataMessage('123', [], messageUtil.getLoginMessage())
- }
|