Skip to content

Instantly share code, notes, and snippets.

@evandrocoan
Created May 20, 2020 01:31
Show Gist options
  • Save evandrocoan/f853821f22c0f19ee9d3b264900361d2 to your computer and use it in GitHub Desktop.
Save evandrocoan/f853821f22c0f19ee9d3b264900361d2 to your computer and use it in GitHub Desktop.
let is_running_wrapper = target_function => {
    return (...args: any) => {
        if (this.is_running_pause) {
            return;
        }
        let result;
        this.is_running_pause = true;
        try {
            result = target_function(...args);
        } catch (error) {
            this.is_running_pause = false;
            throw error;
        }
        this.is_running_pause = false;
        return result;
    };
}
let wrapped_pause = is_running_wrapper(auto_pause);
  1. https://stackoverflow.com/questions/2141520/javascript-variable-number-of-arguments-to-function
  2. https://stackoverflow.com/questions/12697275/open-ended-function-arguments-with-typescript
  3. https://javascript.info/call-apply-decorators
  4. https://stackoverflow.com/questions/31771856/decorators-on-functions
  5. https://stackoverflow.com/questions/3734236/how-can-i-rethrow-an-exception-in-javascript-but-preserve-the-stack
  6. https://www.typescriptlang.org/docs/handbook/decorators.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment