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

112
Vistas
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 Respuestas
Responde la pregunta

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 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