Skip to content

Commit

Permalink
Merge pull request #21 from tcavenezuela/feat/listen-interval-switch
Browse files Browse the repository at this point in the history
chore: add param in listen function to enable or disable interval
  • Loading branch information
carl0shd authored Jul 1, 2024
2 parents ad1b1fd + 94b996e commit 759f914
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 759f914

Please sign in to comment.