sounder code (fixed a memory leak that's not happening with current usage)
Massimo Melina committed
Feb 5, 2022 at 12:35 UTC
6085a82abab0f6a6bc191d0324822d32dc2e0873
1 file changed
+8
-9
src/config.ts
+8
-9
@@ -4,6 +4,7 @@ import { watchLoad } from './watchLoad'
4
import fs from 'fs/promises'
5
import yaml from 'yaml'
6
import _ from 'lodash'
7
+import { onOffMap } from './misc'
8
9
export const CFG_ALLOW_CLEAR_TEXT_LOGIN = 'allow_clear_text_login'
10
@@ -40,16 +41,14 @@ export function subscribeConfig({ k, ...definition }:{ k:string } & ConfigProps,
41
if (a !== undefined)
42
return cb(caster ? caster(a) : a)
43
const eventName = 'new.'+k
43
- emitter.on(eventName, cb)
44
- if (!started) return
45
- let v = state[k]
46
- if (v === undefined)
47
- v = defaultValue
48
- if (v !== undefined)
49
- cb(v)
50
- return () => {
51
- emitter.off(eventName, cb)
44
+ if (started) {
45
+ let v = state[k]
46
+ if (v === undefined)
47
+ v = defaultValue
48
+ if (v !== undefined)
49
+ cb(v)
50
}
51
+ return onOffMap(emitter, { [eventName]: cb })
52
}
53
54
export function getConfig(k:string) {