Call a listener with sync-throw and async-rejection both routed to logError.
(listener: GrowthBookRefreshListener)
| 108 | |
| 109 | /** Call a listener with sync-throw and async-rejection both routed to logError. */ |
| 110 | function callSafe(listener: GrowthBookRefreshListener): void { |
| 111 | try { |
| 112 | // Promise.resolve() normalizes sync returns and Promises so both |
| 113 | // sync throws (caught by outer try) and async rejections (caught |
| 114 | // by .catch) hit logError. Without the .catch, an async listener |
| 115 | // that rejects becomes an unhandled rejection — the try/catch |
| 116 | // only sees the Promise, not its eventual rejection. |
| 117 | void Promise.resolve(listener()).catch(e => { |
| 118 | logError(e) |
| 119 | }) |
| 120 | } catch (e) { |
| 121 | logError(e) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Register a callback to fire when GrowthBook feature values refresh. |
no test coverage detected