refactor: fetcher接口调整,返回channel来通知任务成功和失败

This commit is contained in:
liwei committed 2021-03-11 15:41:35 +08:00
1 parent 74d0e8e0bc
commit 79a93d5b50
5 files changed
+78 -66

No files matched your search

+6 -3
View File
@@ -2,7 +2,7 @@ package base
// 对应协议的下载支持
type Fetcher interface {
Init(ctl Controller)
Setup(ctl Controller) (err <-chan error)
// 解析请求
Resolve(req *Request) (res *Resource, err error)
// 创建任务
@@ -13,9 +13,12 @@ type Fetcher interface {
}
type DefaultFetcher struct {
Ctl Controller
Ctl Controller
DoneCh chan error
}
func (f *DefaultFetcher) Init(ctl Controller) {
func (f *DefaultFetcher) Setup(ctl Controller) (doneCh <-chan error) {
f.Ctl = ctl
f.DoneCh = make(chan error, 1)
return f.DoneCh
}