MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / sleep

Function sleep

ai/ai.ts:1005–1029  ·  view source on GitHub ↗
(ms: number, token?: AbortToken)

Source from the content-addressed store, hash-verified

1003
1004const sleep = (ms: number, token?: AbortToken): Promise<void> => {
1005 return new Promise<void>((resolve, reject) => {
1006 token?.throwIfAborted();
1007 let settled = false;
1008 const cleanup = () => {
1009 if (!token?.signal) return;
1010 token.signal.removeEventListener("abort", abortHandler);
1011 };
1012 const timeoutId = setTimeout(() => {
1013 if (settled) return;
1014 settled = true;
1015 cleanup();
1016 resolve();
1017 }, ms);
1018 const abortHandler = () => {
1019 if (settled) return;
1020 settled = true;
1021 clearTimeout(timeoutId);
1022 cleanup();
1023 reject(new UserError(token?.reason?.toString() || "操作已取消"));
1024 };
1025 if (token?.signal)
1026 token.signal.addEventListener("abort", abortHandler, { once: true });
1027 });
1028};
1029
1030const retryWithFixedDelay = async <T>(
1031 operation: () => Promise<T>,
1032 maxRetries: number = 2,

Callers 12

retryWithFixedDelayFunction · 0.70
pollTaskFunction · 0.70
sendLongMessageMethod · 0.70
addOrUpdateAdminMethod · 0.50
searchAndSendMusicFunction · 0.50
ZhijiaoPluginClass · 0.50
addTemporaryAdminMethod · 0.50
lifecycleSleepFunction · 0.50
forwardToTargetFunction · 0.50
getBotResponseFunction · 0.50
sendCheckinCommandFunction · 0.50
fetchAndSendAudioFunction · 0.50

Calls 2

cleanupFunction · 0.70
throwIfAbortedMethod · 0.65

Tested by

no test coverage detected