github.com/anacrolix/torrent@v1.61.0/tests/issue-930/noServer.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/signal"
     7  	"syscall"
     8  
     9  	"github.com/anacrolix/torrent/metainfo"
    10  )
    11  
    12  func noServer() {
    13  	fmt.Println("Ctrl+C to start downloading")
    14  	sc := make(chan os.Signal, 1)
    15  	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
    16  	<-sc
    17  
    18  	for _, hash := range infoHashes {
    19  		t, _ := client.AddTorrentInfoHash(metainfo.NewHashFromHex(hash))
    20  		infoHash := hash
    21  		go func() {
    22  			<-t.GotInfo()
    23  			fmt.Println("Download started for", infoHash)
    24  			t.DownloadAll()
    25  		}()
    26  	}
    27  
    28  	client.WaitAll()
    29  	fmt.Println("All torrents downloaded")
    30  
    31  	fmt.Println("Ctrl+C to stop program")
    32  	sc2 := make(chan os.Signal, 1)
    33  	signal.Notify(sc2, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
    34  	<-sc2
    35  }