rename Update to Transact
This commit is contained in:
parent
bef160745a
commit
587b7f38ce
2
db/db.go
2
db/db.go
@ -56,7 +56,7 @@ func (d *Db) Add(i Item) (int, bool) {
|
||||
return i.Id, true
|
||||
}
|
||||
|
||||
func (d *Db) Update(id int, persist bool, f func(*Item)) error {
|
||||
func (d *Db) Transact(id int, persist bool, f func(*Item)) error {
|
||||
d.mutex.Lock()
|
||||
defer d.mutex.Unlock()
|
||||
for i, _ := range d.items {
|
||||
|
16
main.go
16
main.go
@ -108,7 +108,7 @@ func main() {
|
||||
}
|
||||
fmt.Println("path is", p, "id is", id)
|
||||
var sc <-chan string
|
||||
d.Update(id, false, func(i *db.Item) {
|
||||
d.Transact(id, false, func(i *db.Item) {
|
||||
pt := i.Pt
|
||||
if pt != nil {
|
||||
sc = pt.Subscribe()
|
||||
@ -127,7 +127,7 @@ func main() {
|
||||
}
|
||||
var status db.DownloadStatus
|
||||
var fname string
|
||||
d.Update(id, true, func(i *db.Item) {
|
||||
d.Transact(id, false, func(i *db.Item) {
|
||||
status = i.Status
|
||||
fname = i.FileName
|
||||
})
|
||||
@ -154,12 +154,12 @@ func main() {
|
||||
}
|
||||
|
||||
var tc <-chan struct{}
|
||||
d.Update(id, false, func(i *db.Item) {
|
||||
d.Transact(id, false, func(i *db.Item) {
|
||||
tc = i.TitleChan
|
||||
})
|
||||
<-tc
|
||||
var title string
|
||||
d.Update(id, false, func(i *db.Item) {
|
||||
d.Transact(id, false, func(i *db.Item) {
|
||||
title = i.Title
|
||||
})
|
||||
w.Write([]byte(title))
|
||||
@ -171,7 +171,7 @@ func main() {
|
||||
func getTitle(id int, yturl string) {
|
||||
tc := make(chan struct{})
|
||||
defer close(tc)
|
||||
d.Update(id, false, func(i *db.Item) {
|
||||
d.Transact(id, false, func(i *db.Item) {
|
||||
i.TitleChan = tc
|
||||
})
|
||||
args := append(ytdlCmd, "--get-title", yturl)
|
||||
@ -183,14 +183,14 @@ func getTitle(id int, yturl string) {
|
||||
} else {
|
||||
title = string(op)
|
||||
}
|
||||
d.Update(id, true, func(i *db.Item) {
|
||||
d.Transact(id, true, func(i *db.Item) {
|
||||
i.Title = title
|
||||
})
|
||||
}
|
||||
|
||||
func download(id int, yturl string) {
|
||||
pt := pubsub.NewProgressTracker()
|
||||
d.Update(id, true, func(i *db.Item) {
|
||||
d.Transact(id, true, func(i *db.Item) {
|
||||
i.Status = db.InProgress
|
||||
i.Pt = pt
|
||||
})
|
||||
@ -220,7 +220,7 @@ func download(id int, yturl string) {
|
||||
} else {
|
||||
status = db.Done
|
||||
}
|
||||
d.Update(id, true, func(i *db.Item) {
|
||||
d.Transact(id, true, func(i *db.Item) {
|
||||
i.Status = status
|
||||
i.FileName = fname
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user