refactor: fetcher模型

This commit is contained in:
liwei committed 2021-03-17 10:26:30 +08:00
1 parent eee6112be5
commit f150ec23c4
9 files changed
+297 -207

No files matched your search

+9 -3
View File
@@ -2,7 +2,7 @@ package base
// 对应协议的下载支持
type Fetcher interface {
Setup(ctl Controller) (err <-chan error)
Setup(ctl Controller)
// 解析请求
Resolve(req *Request) (res *Resource, err error)
// 创建任务
@@ -10,6 +10,9 @@ type Fetcher interface {
Start() (err error)
Pause() (err error)
Continue() (err error)
// 该方法会一直阻塞,直到任务下载结束
Wait() (err error)
}
type DefaultFetcher struct {
@@ -17,8 +20,11 @@ type DefaultFetcher struct {
DoneCh chan error
}
func (f *DefaultFetcher) Setup(ctl Controller) (doneCh <-chan error) {
func (f *DefaultFetcher) Setup(ctl Controller) {
f.Ctl = ctl
f.DoneCh = make(chan error, 1)
return f.DoneCh
}
func (f *DefaultFetcher) Wait() (err error) {
return <-f.DoneCh
}