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

211
Views
Typescript asynchronous decorators decorate synchronous methods

How to correctly identify synchronous methods that have been modified to be asynchronous when using asynchronous decorators to decorate synchronous methods.

function AsyncDecorator() {
  return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
    const originalMethod = descriptor.value;
    descriptor.value = async function (...args: any[]) {
      await sleep(100);
      const result = await originalMethod.apply(this, args);
      return result;
    };
    return descriptor;
  };
}

async function sleep(ms: number) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

class Test {
  // This function appears to be a synchronous function, but has been changed to an asynchronous function by an asynchronous decorator, but I didn't know that
  @AsyncDecorator()
  fun(): string {
    return 'Hello World!';
  }
}

const result = new Test().fun();
console.log(result); // Expect results: Hello World!  Actual result: Promise {<pending>}

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