Skip to content

Commit

Permalink
chore: add param in listen function to enable or disable interval
Browse files Browse the repository at this point in the history
  • Loading branch information
carl0shd committed Jul 1, 2024
1 parent ad1b1fd commit 94b996e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-balloons-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fsuipc.js/api': patch
---

add param in listen function to enable or disable interval
7 changes: 5 additions & 2 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,6 +41,7 @@ export class FsuipcApi {
}

public listen(
useInterval: boolean,
interval: number,
offsetList: string[],
terminateOnError = true
Expand All @@ -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) => {
Expand Down

0 comments on commit 94b996e

Please sign in to comment.