Skip to content
New issue

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

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

Already on GitHub? # to your account

add time out param to ntp function #19

Merged
merged 2 commits into from
Nov 28, 2023
Merged

add time out param to ntp function #19

merged 2 commits into from
Nov 28, 2023

Conversation

Meepoljdx
Copy link
Contributor

通过timeout参数设置ntp的超时时长,单位是s,比如设置成20s

@UlricQin
Copy link
Member

这个改动挺好的,但是不能直接这么改了。因为修改了方法签名导致依赖这些方法的上层代码都会失败,toolkits 下面的内容被多个项目依赖,有些项目可以及时跟进改造,有些项目未必能够跟进及时。所以,这个 timeout 时间可以作为可变参数提供,比如这个方法:

func getTwoTime(host string, version byte, timeout int64) (time.Time, time.Time, err error) {}

可以改成:

func getTwoTime(host string, version byte, timeout ...int64) (time.Time, time.Time, err error) {}

即:用户可以传一个 timeout 进来,也可以不传,不传的话就仍然使用默认的 5s 超时,如果传了,就用新传进来的参数。

@Meepoljdx
Copy link
Contributor Author

这个改动挺好的,但是不能直接这么改了。因为修改了方法签名导致依赖这些方法的上层代码都会失败,toolkits 下面的内容被多个项目依赖,有些项目可以及时跟进改造,有些项目未必能够跟进及时。所以,这个 timeout 时间可以作为可变参数提供,比如这个方法:

func getTwoTime(host string, version byte, timeout int64) (time.Time, time.Time, err error) {}

可以改成:

func getTwoTime(host string, version byte, timeout ...int64) (time.Time, time.Time, err error) {}

即:用户可以传一个 timeout 进来,也可以不传,不传的话就仍然使用默认的 5s 超时,如果传了,就用新传进来的参数。

您说的对,我做了一下修改,将timeout改为了可选参数,如果用户不传入就是用5s超时

@UlricQin UlricQin merged commit 819b4a1 into toolkits:master Nov 28, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants