临时提交

This commit is contained in:
liwei committed 2020-12-30 16:54:36 +08:00
1 parent 3215955056
commit 871185e7ea
5 files changed
+36 -15

No files matched your search

+13
View File
@@ -20,6 +20,7 @@ type Process struct {
chunks []*model.Chunk
pauseCond *sync.Cond
eventCh chan common.Event
}
func NewProcess(fetcher *Fetcher, res *common.Resource, opts *common.Options) *Process {
@@ -33,6 +34,11 @@ func NewProcess(fetcher *Fetcher, res *common.Resource, opts *common.Options) *P
}
}
func (p *Process) Listen() <-chan common.Event {
p.eventCh = make(chan common.Event)
return p.eventCh
}
func (p *Process) Start() error {
ctl := p.fetcher.GetCtl()
// 创建文件
@@ -68,6 +74,7 @@ func (p *Process) Start() error {
p.clients = make([]*http.Response, 1)
p.chunks[0] = model.NewChunk(0, 0)
}
p.dispatch(common.DownloadStatusStart)
return p.fetch()
}
@@ -243,3 +250,9 @@ func (p *Process) fetchChunk(index int, name string, chunk *model.Chunk) (err er
}
return
}
func (p *Process) dispatch(status common.Status) {
if p.eventCh != nil {
p.eventCh <- &Event{status: status}
}
}