Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Need Help] How can I let errorRetryInterval work with pollingInterval #219

Closed
zyxkad opened this issue Oct 16, 2023 · 1 comment
Closed
Labels
question Further information is requested

Comments

@zyxkad
Copy link

zyxkad commented Oct 16, 2023

问题描述 Problem Description

当提供pollingInterval时, errorRetryInterval会被忽略
那么该如何进行指数退避呢?

其他信息 Other information

当前代码:

const ready = ref(false)
const { data: connections } = (() => {
	const pollingInterval = 500
	const maxRetryInterval = 60 * 1000 // a minute
	const errorRetryInterval = ref(pollingInterval)
	return useRequest(() => api.getConnections().catch((e) => {
		if(e instanceof APIError){
			if(e.type === 'AuthError'){
				ready.value = false
				login().then(() => {
					ready.value = true
				})
			}
		}
		throw e
	}), {
		ready: ready,
		pollingInterval: pollingInterval,
		errorRetryInterval: errorRetryInterval,
		onSuccess(){
			console.log('onSuccess')
			errorRetryInterval.value = pollingInterval
		},
		onError(){
			console.log('onError', errorRetryInterval.value = Math.min(errorRetryInterval.value * 2, maxRetryInterval))
		},
	})
})()

onMounted(() => {
	if (!(await api.verify())) {
		await login()
	}
        ready.value = true
})

下图的每一条日志间隔都是500毫秒
Screenshot 2023-10-16 at 1 07 03 PM

@zyxkad zyxkad added the question Further information is requested label Oct 16, 2023
@zyxkad
Copy link
Author

zyxkad commented Oct 16, 2023

好的明白了,应该设置pollingIntervalref

@zyxkad zyxkad closed this as completed Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant