What is Nostr?
P-Y /
npub19ww…g5sa
2024-01-17 06:13:38
in reply to nevent1q…gmh4

P-Y on Nostr: Everybody loves singletons, so we gotta have singleton support! Let's add a ...

Everybody loves singletons, so we gotta have singleton support!

Let's add a `installSingleton()` utility, that will leverage the `install()` utility we just defined:

```
inline fun <reified T> Linker.installSingleton(noinline factory: Linker.() -> T) {
var instance = UNINITIALIZED
install {
if (instance === UNINITIALIZED) {
instance = factory()
}
instance as T
}
}

var UNINITIALIZED: Any? = Any()
```

(This isn't thread safe. Who cares?)
Author Public Key
npub19wwxc29uufy6rmegf9aza3hkcqdu00s8yyfyhr88mglptysgp3tsz7g5sa