Made Torrent.GotInfo a function, to avoid use of zero-initialized channel
This commit is contained in:
parent
0ec0302d1c
commit
ca74d8ed33
|
@ -643,7 +643,7 @@ func (cl *Client) Torrent(ih InfoHash) (T Torrent, ok bool) {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
T = Torrent{cl, t, t.gotMetainfo}
|
||||
T = Torrent{cl, t}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2612,7 +2612,7 @@ func (cl *Client) verifyPiece(t *torrent, index pp.Integer) {
|
|||
func (me *Client) Torrents() (ret []Torrent) {
|
||||
me.mu.Lock()
|
||||
for _, t := range me.torrents {
|
||||
ret = append(ret, Torrent{me, t, t.gotMetainfo})
|
||||
ret = append(ret, Torrent{me, t})
|
||||
}
|
||||
me.mu.Unlock()
|
||||
return
|
||||
|
|
|
@ -26,7 +26,7 @@ func main() {
|
|||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
<-t.GotInfo
|
||||
<-t.GotInfo()
|
||||
mi := t.MetaInfo()
|
||||
t.Drop()
|
||||
f, err := os.Create(mi.Info.Name + ".torrent")
|
||||
|
|
|
@ -128,7 +128,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
<-t.GotInfo
|
||||
<-t.GotInfo()
|
||||
t.DownloadAll()
|
||||
}()
|
||||
}
|
||||
|
|
11
t.go
11
t.go
|
@ -10,10 +10,13 @@ import (
|
|||
type Torrent struct {
|
||||
cl *Client
|
||||
*torrent
|
||||
// Closed when the info (.Info()) for the torrent has become available.
|
||||
// Using features of Torrent that require the info before it is available
|
||||
// will have undefined behaviour.
|
||||
GotInfo <-chan struct{}
|
||||
}
|
||||
|
||||
// Closed when the info (.Info()) for the torrent has become available. Using
|
||||
// features of Torrent that require the info before it is available will have
|
||||
// undefined behaviour.
|
||||
func (t *Torrent) GotInfo() <-chan struct{} {
|
||||
return t.torrent.gotMetainfo
|
||||
}
|
||||
|
||||
func (t *Torrent) Info() *metainfo.Info {
|
||||
|
|
Loading…
Reference in New Issue