0

Hi i want to keep getting data even after the timeout its reached i try some other way but no success (timeWith, repeatWhen ect)

here my code. now, any help would be good

goal: Device stops sending data = timeout alert user, device starts to get data again resume stream

  private gpsDevice(): Observable<Position> {
    return this.bluetooth.getBluetoothData().pipe(
      timeout(4000),
      switchMap((position) => {
       ...
        return of(position);
      }),
      catchError((error) => {
        console.error('Timeout occurred:', error);

        return EMPTY;
      }),
    );
  }
2
  • 1
    So you want to trigger an alert when the time is reached rather than throw an error? Commented Jan 9, 2024 at 19:35
  • i can throw an error nu the stream will be stopped i want to alert the user or send a error but not stop the stream Commented Jan 10, 2024 at 21:06

1 Answer 1

1

Take a look at the docs for that operator here.

You can use the with field to provide a callback when the timeout fires. That callback does not necessarily need to throw an error. Instead it could fire off a side effect that triggers a toast message, for example.

mySlowObservable$.pipe( timeout({ each: 5000, with: () => { trigger a toast message here }, }) )

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.