-
Notifications
You must be signed in to change notification settings - Fork 0
/
progess.go
52 lines (40 loc) · 1.18 KB
/
progess.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package onearchiver
import (
rxgo "github.com/ReactiveX/RxGo"
"time"
)
func initProgress(totalFiles int, ph *ProgressHandler) (*ProgressInfo, *chan rxgo.Item) {
pInfo := ProgressInfo{
StartTime: time.Now(),
TotalFiles: totalFiles,
ProgressCount: 0,
CurrentFilename: "",
ProgressPercentage: 0,
}
ch := make(chan rxgo.Item)
observable := rxgo.FromChannel(ch)
observable.ForEach(func(v interface{}) {
ph.OnReceived(&pInfo)
}, func(err error) {
ph.OnError(err, &pInfo)
}, func() {
ph.OnCompleted(&pInfo)
})
return &pInfo, &ch
}
func (pInfo *ProgressInfo) progress(ch *chan rxgo.Item, totalFiles int, absolutePath string, progressCount int) {
progressPercentage := Percent(float32(progressCount), float32(totalFiles))
pInfo.TotalFiles = totalFiles
pInfo.ProgressCount = progressCount
pInfo.CurrentFilename = absolutePath
pInfo.ProgressPercentage = progressPercentage
*ch <- rxgo.Of(pInfo)
}
func (pInfo *ProgressInfo) endProgress(ch *chan rxgo.Item, totalFiles int) {
pInfo.TotalFiles = totalFiles
pInfo.ProgressCount = totalFiles
pInfo.CurrentFilename = ""
pInfo.ProgressPercentage = 100.00
*ch <- rxgo.Of(pInfo)
defer close(*ch)
}