GithubHelp home page GithubHelp logo

Comments (5)

littledan avatar littledan commented on August 16, 2024 1

I think you can implement the @catch decorator in the current proposal by using a decorator which replaces the value of the element's property descriptor with another function which does the catching. You could also use try/catch in your async function, of course. For bound methods, this repository contains source for an @bound decorator, or you could use a field declaration with an arrow function.

from proposal-decorators.

ljharb avatar ljharb commented on August 16, 2024

Could your "catch" decorator not return function (...args) { return original.call(this, ...args).catch(this.errorHandler); }, without any need for ::?

iow, it'd be like:

class {
  @catch(this.errorHandler)
  async handler(e) {
    
  }

  errorHandler(e) {
    this.e = e;
    console.error(e);
  }

from proposal-decorators.

ljharb avatar ljharb commented on August 16, 2024

ah, after updating my comment to include a code sample, you're asking primarily about the this.errorHandler - and it's a bit awkward to do @catch(function (...args) { return this.errorHandler(...args); }).

from proposal-decorators.

haraldrudell avatar haraldrudell commented on August 16, 2024

If you’re an async function or a promise and your invoker is not, ie. the invocation does not have await, then you are often going to need an onReject function

The onReject functions are typically bound or static, and a class method or a function value provided to the constructor

error handler functions are typically shared by multiple or even all async functions and promises

from proposal-decorators.

littledan avatar littledan commented on August 16, 2024

Please reopen this issue if you have any concerns with this response. As far as I can tell, your requirements are met by the current proposal.

from proposal-decorators.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.