feat: display delay check result timely

This commit is contained in:
GyDi
2022-10-26 01:11:02 +08:00
parent 947c38c124
commit 14f627d0d3
9 changed files with 179 additions and 138 deletions

View File

@@ -49,6 +49,14 @@ const ProxyItem = (props: Props) => {
// -2 为 loading
const [delay, setDelay] = useState(-1);
useEffect(() => {
delayManager.setListener(proxy.name, groupName, setDelay);
return () => {
delayManager.removeListener(proxy.name, groupName);
};
}, [proxy.name, groupName]);
useEffect(() => {
if (!proxy) return;
@@ -66,10 +74,7 @@ const ProxyItem = (props: Props) => {
const onDelay = useLockFn(async () => {
setDelay(-2);
return delayManager
.checkDelay(proxy.name, groupName)
.then((result) => setDelay(result))
.catch(() => setDelay(1e6));
setDelay(await delayManager.checkDelay(proxy.name, groupName));
});
return (