Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
Execute methods one by one in Angular and RxJS
this.userClient.getUser(userName)
.pipe(
    concatMap(
        user => { 
            this.user = user;
            return this.userClient.setStatus(this.user.id, 'banned');
        }
    ),
    concatMap(
        user => {
            //set property...
            return this.userClient.deleteImg(user.img);
        }
    ),
    mergeMap(
        user => {
            this.user = user;
            return this.userClient.setGroup(user.id, 'test');
        }
    )
)
.subscribe(
    user => {
        //actions
    },
    error => ...
)

I would like my methods to be turned on one by one, not all at once. how can I do this? forkJoin is the only way out?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Keep the first switchMap, but then return a concat. The concat will sequence the three items you wish for. Concat waits until one is done, then does the next, and so on.

You can find more info on concat on the RxjS Concat docs

this.userClient.getUser(userName)
  .pipe(
    switchMap(
      user => { 
        this.user = user;
        return concat(
            this.userClient.setStatus(this.user.id, 'banned'),
            this.userClient.deleteImg(user.img),
            this.userClient.setGroup(user.id, 'test')
        );
    }
)
)
.subscribe(
  ([user]) => {
    //actions
  },
  error => ...
)

On an episode of the Angular Show they described some of these Higher Order Mapping Operators. It may help understand how these work.

over 4 years ago · Santiago Trujillo Relatório

0

Just use switchMap

this.userClient.getUser(userName)
.pipe(
    switchMap(
        user => { 
            this.user = user;
            return this.userClient.setStatus(this.user.id, 'banned');
        }
    ),
    switchMap(
        user => {
            //set property...
            return this.userClient.deleteImg(user.img);
        }
    ),
    switchMap(
        user => {
            this.user = user;
            return this.userClient.setGroup(user.id, 'test');
        }
    )
)
.subscribe(
    user => {
        //actions
    },
    error => ...
)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda