Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
Unsubscribe observable in an Angular service

I want to unsubscribe an observable in an angular service once a certain state is present. The unsubscribe should be executed within the subscription. Unfortunately the code below does not work.

@Injectable()
export class CartManagementUsecase {
  private unsubscribe = new Subject();

  public streamSession(): void {
    this.adapter
        .streamSession()
        .pipe(takeUntil(this.unsubscribe))
        .subscribe((session) => {
          if(session.session_state === SessionState.CLOSED) {
            this.unsubscribe.unsubscribe();
          }
    });
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I would recommend you to take events untill closed is come. no subject would be required

public streamSession(): void {
    this.adapter
        .streamSession()
        .pipe(takeWhile(session => session.session_state != SessionState.CLOSED))
        .subscribe((session) => {
          // do something that is required
        });
  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to call complete on your subject for takeUntil to unsubscribe to the observable.

@Injectable()
export class CartManagementUsecase {
  private unsubscribe = new Subject();

  public streamSession(): void {
    this.adapter
        .streamSession()
        .pipe(takeUntil(this.unsubscribe))
        .subscribe((session) => {
          if(session.session_state === SessionState.CLOSED) {
            this.unsubscribe.complete();
          }
    });
  }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda