Skip to content
Snippets Groups Projects
Commit c6b9057d authored by paf's avatar paf
Browse files

imporve way to ensure minimum delay between command executions

parent 7badf037
No related branches found
No related tags found
No related merge requests found
import {Inject, Injectable, OnDestroy} from '@angular/core'; import {Inject, Injectable, OnDestroy} from '@angular/core';
import {interval, of, Subject, Subscription} from 'rxjs'; import {of, Subject, Subscription, timer} from 'rxjs';
import {Command, commandKeywords, isKnownCommand, TestStatus} from './test-controller.interfaces'; import {Command, commandKeywords, isKnownCommand, TestStatus} from './test-controller.interfaces';
import {TestControllerService} from './test-controller.service'; import {TestControllerService} from './test-controller.service';
import {distinctUntilChanged, filter, map, mergeMap, switchMap, tap, zip} from 'rxjs/operators'; import {
concatMap,
distinctUntilChanged,
filter,
ignoreElements,
map,
mergeMap,
startWith,
switchMap
} from 'rxjs/operators';
import {Uuid} from '../shared/uuid'; import {Uuid} from '../shared/uuid';
import {WebsocketBackendService} from '../shared/websocket-backend.service'; import {WebsocketBackendService} from '../shared/websocket-backend.service';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
...@@ -84,8 +93,7 @@ export class CommandService extends WebsocketBackendService<Command[]> implement ...@@ -84,8 +93,7 @@ export class CommandService extends WebsocketBackendService<Command[]> implement
private subscribeCommands() { private subscribeCommands() {
this.commandSubscription = this.command$ this.commandSubscription = this.command$
.pipe( .pipe(
zip<Command, number>(interval(150)), // ensure that a minim to time is between two commands concatMap(item => timer(300).pipe(ignoreElements(), startWith(item))), // min delay between items
map(v => v[0]),
mergeMap((command: Command) => { mergeMap((command: Command) => {
console.log('try to execute' + CommandService.commandToString(command)); console.log('try to execute' + CommandService.commandToString(command));
return this.http.patch(`${this.serverUrl}test/${this.tcs.testId}/command/${command.id}/executed`, {}) return this.http.patch(`${this.serverUrl}test/${this.tcs.testId}/command/${command.id}/executed`, {})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment