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

121
Visualizações
Difference between de-novo async function vs conversion of a simple synchronous function with a Promise?

In order to minimize code duplication, I've written some simple JS/TS async functions by encapsulating the respective synchronous function within a Promise. But, not seeing this elsewhere, I'm concerned that I may be missing some design problem(s).

For example:

function fileExistsSync(path: string) {
    try {
        const result = Deno.statSync(path);
        return result.isFile;
    } catch (err) {
        if (err instanceof Deno.errors.PermissionDenied) {
            throw err;
        }
        return false;
    }
}

async function fileExists(path: string) {
    return await Promise.resolve().then(() => fileExistsSync(path));
}

async function fileExistsAsync(path: string) {
    try {
        const result = await Deno.stat(path);
        return result.isFile;
    } catch (err) {
        if (err instanceof Deno.errors.PermissionDenied) {
            throw err;
        }
        return false;
    }
}

Is there any observable difference between the functions fileExists() and fileExistsAsync()?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, because fileExists uses Deno.statSync where fileExistsAsync uses Deno.stat.

The sync versions of IO functions block the entire JS execution runtime, while the promise/async Deno.stat version allows other JS code to continue to execute while waiting for a result.

about 4 years ago · Juan Pablo Isaza 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