Creating an async singletone in javascript
问题 I need to implement an async singleton, that creates a single instance of a class that requires asynchronous operations in order to pass arguments to the constructor. I have the following code: class AsyncComp { constructor(x, y) { this.x = x; this.y = y; } // A factory method for creating the async instance static async createAsyncInstance() { const info = await someAsyncFunction(); return new AsyncComp(info.x, info.y); } // The singleton method static getAsyncCompInstance() { if