From 1228b3f17dfaf9c699ebd788bed8be35b1e14f12 Mon Sep 17 00:00:00 2001 From: Il Harper Date: Tue, 10 Sep 2024 14:38:36 +0800 Subject: [PATCH] fix(api): `groupNotify.refresh()` adapt delay-debounce --- .../src/services/groupNotify.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/engine-chronocat-api/src/services/groupNotify.ts b/packages/engine-chronocat-api/src/services/groupNotify.ts index 6219025..7dab293 100644 --- a/packages/engine-chronocat-api/src/services/groupNotify.ts +++ b/packages/engine-chronocat-api/src/services/groupNotify.ts @@ -1,13 +1,7 @@ +import { debounce } from 'lodash-es' import { getSingleScreenNotifies } from '../definitions/groupService' -let t = new Date().getTime() - -const refresh = async () => { - const nt = new Date().getTime() - - if (nt - t < 10000) return - t = nt - +const refreshIntl2 = async () => { void getSingleScreenNotifies({ doubt: false, startSeq: '', @@ -20,6 +14,12 @@ const refresh = async () => { }) } +const refreshIntl1 = debounce(refreshIntl2, 2000, { + maxWait: 2000, +}) + +const refresh = () => setTimeout(refreshIntl1, 2000) + export const groupNotify = { refresh, }