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

165
Visualizações
Javascript, async functions behave differently between Mac and Windows/Linux

await/async seem to behave differently on Chrome and Safari on Mac, compared to Chrome on Windows and Linux.

<select id="dbgselect">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

<script>
    async function dbg(type) {
        console.log(`A [${type}]`);
        await dbg2(type);
        console.log(`B [${type}]`);
    }
    
    async function dbg2(type) {
        console.log(`C [${type}]`);
    }
    
    document.getElementById("dbgselect").oninput = () => { dbg("input"); };
    document.getElementById("dbgselect").onchange = () => { dbg("change"); };
</script>

When making a selection in the dropdown, the output on Linux/Windows (on Chrome) is:

A [input]
C [input]
A [change]
C [change]
B [input]
B [change]

The output on Mac (on both Chrome and Safari):

A [input]
C [input]
B [input]
A [change]
C [change]
B [change]

HOWEVER - if I add this at the bottom, to invoke dbg outside the context of an event:

setTimeout(() => {
    dbg("input");
    dbg("change");
}, 0);

Then the result on Mac changes, and becomes the same as on Linux and Windows (i.e. A,C,A,C,B,B instead of A,C,B,A,C,B).

My questions:

  1. Is either of these implementations a bug? (i.e. a violation of some standard).

  2. Is this difference in behavior documented or discussed anywhere? I couldn't find.

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