Decorator to reuse promises while they're pending, and optionally cache the result forever
class MyClass { // Reuse promise while pending (default behavior) @reusable() async fetchData() { return await fetch('...'); } // Cache result forever (singleton pattern) @reusable({forever: true}) async init() { // This will only run once return await this.setup(); }} Copy
class MyClass { // Reuse promise while pending (default behavior) @reusable() async fetchData() { return await fetch('...'); } // Cache result forever (singleton pattern) @reusable({forever: true}) async init() { // This will only run once return await this.setup(); }}
Decorator to reuse promises while they're pending, and optionally cache the result forever