Type of the promised value to be lazy-constructed.
Initializer Constructor.
Create a new Singleton
instance with the lazy consturctor.
Lazy constructor function returning the promised value.
Get promised value.
Singleton.get()
method returns the lazy constructed value*. It guarantees the *lazy
constructor to be called *"only one at time". It ensures the *"only one at time", even
in the race condition.
If the promised value is not constructed yet (call this method at the first time), the lazy constructor would be called and returns the promised value. Otherwise, the promised value has been already constructed by the lazy constructor (this method already had been called), returns the pre-generated value.
Also, you don't need to worry anything even race condition has been occured, calling
Singleton.get()
simultaneously when the lazy construction is not completed but on
going. The Singleton
guarantees the lazy constructor to be called only one at time by
using the unique-lock on a mutex.
The lazy constructed value.
Reload value.
The Singleton.reload()
method enforces to call the lazy constructor, regardless of
whether the lazy construction has been completed or not. Therefore, even if the lazy
construction has been completed in sometime, the Singleton.reload()
will call the lazy
constructor again.
However, unlike Singleton.get(), Singleton.reload()
does not ensure the safety
in the race condition. Therefore, you've to be careful by yourself when using this
Singleton.reload()
method. Try not to call this method simultaneously.
Re-constructed value.
Generated using TypeDoc
Asynchronous Singleton Generator.
The
Singleton
is an asynchronous singleton generator class who guarantees the lazy constructor to be called *"only one at time". The *"only one at time" would always be kepted, even in the race condition.Create a
Singleton
instance with your custom lazy constructor and get the promised value through the Singleton.get() method. The Singleton.get() method would construct the return value following below logics:If you want to reload the promised value, regardless of whether the lazy construction has been completed or not, call the Singleton.reload() method. It would call the lazy constructor forcibly, even if the lany construction has been completed in sometime.
Jeongho Nam - https://github.com/samchon