Closed osher closed 7 years ago
My task now is to glue few legacy codes that use some singleton that was replaced in modern codes with a contextified instance.
I need to use the contextified instance whenever it's available, and fallback to the infamous singleton whenver it's not found.
I did notice that when I try to get or set a value when I'm not in a context of an async handler an exception is thrown.
The access to this model is very common. I cannot afford to try { return ns.get(name) } catch(e) { return fallbackToSingleton }.
try { return ns.get(name) } catch(e) { return fallbackToSingleton }
Is there a way I can check if I'm in a context or not?
aha. I take it back. the throw is only for .set
.set
so the right way is probably return ns.get(name) || fallbackToSingleton
return ns.get(name) || fallbackToSingleton
If I'm mistaking - let me know
That's an appropriate way to handle it. 👍
My task now is to glue few legacy codes that use some singleton that was replaced in modern codes with a contextified instance.
I need to use the contextified instance whenever it's available, and fallback to the infamous singleton whenver it's not found.
I did notice that when I try to get or set a value when I'm not in a context of an async handler an exception is thrown.
The access to this model is very common. I cannot afford to
try { return ns.get(name) } catch(e) { return fallbackToSingleton }
.Is there a way I can check if I'm in a context or not?