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

91
Visualizações
Is the JavaScript promise handler determined by the order of its functions?
exports.userDidSignOut = functions.https.onCall((data) => {
    const userId = data.userId;
    const settingsUpdate = {
        "fcmToken": null,
    };
    const promise = admin.firestore().collection("user-settings").doc(userId).update(settingsUpdate);

    promise.then(
        (_value) => {
            return null;
        },
        (reason) => {
            return console.log(reason);
        }
    );
});

I'm working with a database (Firestore) that returns a promise when data is updated. In this snippet above, I update the database with update() and it returns a value parameter on success and a reason parameter on failure. Because I can rename these parameters freely, how does the promise know which function is the success and which is the error? Is it purely based on the order they appear? And can I remove the value parameter entirely and will the promise know that's the function to call on success?

promise.then(
    () => {
        return null; // is removing the parameter of this function safe to do?
    },
    (reason) => {
        return console.log(reason);
    }
);
about 4 years ago · Juan Pablo Isaza
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