Skip to content

Instantly share code, notes, and snippets.

@clintonmedbery
Created November 22, 2021 16:21
Show Gist options
  • Save clintonmedbery/3b2c3a730bafc7abe066feaaff87aa2f to your computer and use it in GitHub Desktop.
Save clintonmedbery/3b2c3a730bafc7abe066feaaff87aa2f to your computer and use it in GitHub Desktop.
Example of a async singleton class
export class TestServer {
static _instance: TestServer;
static app: Thing;
constructor() {
return (async () => {
if (TestServer._instance) {
return TestServer._instance;
}
const app = await Something();
TestServer.app = app;
TestServer._instance = this;
return this;
})();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment