Skip to content

Commit 216d220

Browse files
Update libs/hooks/debounce/src/lib/debounce-hook.ts
Co-authored-by: Lukas Reining <[email protected]> Signed-off-by: Todd Baert <[email protected]>
1 parent 91ef84d commit 216d220

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libs/hooks/debounce/src/lib/debounce-hook.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class DebounceHook<T extends FlagValue = FlagValue> implements BaseHook {
182182
// server hooks can be async, web hooks can't, we have to handle both cases.
183183
try {
184184
const maybePromiseOrContext = hookCallback.call(this.innerHook);
185-
if (maybePromiseOrContext && typeof maybePromiseOrContext.then === 'function') {
185+
if (this.isPromise(maybePromiseOrContext)) {
186186
// async hook result; cache after promise resolves
187187
maybePromiseOrContext
188188
.then((maybeContext) => {
@@ -195,7 +195,7 @@ export class DebounceHook<T extends FlagValue = FlagValue> implements BaseHook {
195195
});
196196
} else {
197197
// sync hook result; cache now
198-
this.cacheSuccess(cacheKey, stage, got, maybePromiseOrContext as void | EvaluationContext);
198+
this.cacheSuccess(cacheKey, stage, got, maybePromiseOrContext);
199199
}
200200
return maybePromiseOrContext;
201201
} catch (error: unknown) {
@@ -204,6 +204,10 @@ export class DebounceHook<T extends FlagValue = FlagValue> implements BaseHook {
204204
}
205205
}
206206

207+
private isPromise<T>(value: T | Promise<T>): value is Promise<T> {
208+
return !!value && typeof (value as Promise<unknown>).then === 'function';
209+
}
210+
207211
private cacheSuccess(
208212
key: string,
209213
stage: Stage,

0 commit comments

Comments
 (0)