Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!