diff --git a/.changeset/stale-balloons-stare.md b/.changeset/stale-balloons-stare.md new file mode 100644 index 0000000..61752e1 --- /dev/null +++ b/.changeset/stale-balloons-stare.md @@ -0,0 +1,5 @@ +--- +'@fsuipc.js/api': patch +--- + +add param in listen function to enable or disable interval diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index c4383a8..583bcfb 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -1,5 +1,5 @@ import { FSUIPC, Simulator, Type, FSUIPCError } from 'fsuipc.js'; -import { timer, from, Observable, throwError } from 'rxjs'; +import { timer, from, Observable, throwError, of } from 'rxjs'; import { switchMap, catchError, map } from 'rxjs/operators'; // Utils @@ -41,6 +41,7 @@ export class FsuipcApi { } public listen( + useInterval: boolean, interval: number, offsetList: string[], terminateOnError = true @@ -51,7 +52,9 @@ export class FsuipcApi { this.watchOffsets(offsetList); - return timer(interval, interval).pipe( + const source$ = useInterval ? timer(interval, interval) : of(null); + + return source$.pipe( switchMap(() => from(this.fsuipc.process()).pipe( map((result: object) => {