const mutexify = require('mutexify/promise')
const lock = mutexify()
class Singleton {
private static _instance: Singleton
private constructor() {}
static async getInstance() {
if (!this._instance) {
const release = await lock()
!this._instance && (this._instance = new A())
release()
}
return this._instance
}
log() {
console.log('싱글이야?')
}
}
const a = Singleton.getInstance()
a.log()
SOLID 원칙 중 아래 두 가지를 위반한다.
이유에 대해선 여기를 보면 힌트를 얻을 수 있을 것 같다.