Migrate to remotes interface

This commit is contained in:
2024-01-16 12:48:42 -05:00
parent 5337ea544b
commit e7f8b86f72
13 changed files with 160 additions and 283 deletions

View File

@@ -17,8 +17,8 @@ const (
type Remotes []remote.Remote
func (r *Remotes) AddRemote(remote remote.Remote) {
*r = append(*r, remote)
func (r *Remotes) AddRemotes(remote ...remote.Remote) {
*r = append(*r, remote...)
}
func (r *Remotes) GetRemoteByHost(host string) remote.Remote {
@@ -31,20 +31,18 @@ func (r *Remotes) GetRemoteByHost(host string) remote.Remote {
}
// Launches project streamsers for all remotes in goroutines
// returns slice of load.ProgressInfo
func (r *Remotes) StreamRemotes(opts *remote.RemoteQueryOpts) []*load.ProgressInfo {
progressInfos := make([]*load.ProgressInfo, len(*r))
for i, remoteInstance := range *r {
progressInfos[i] = &load.ProgressInfo{
ProgressChan: make(chan load.Progress),
ProjectsChan: make(chan []*projects.Project),
ErrorChan: make(chan error),
DoneChan: make(chan interface{}),
NumProjects: remoteInstance.GetNumProjects(opts),
}
go remoteInstance.StreamProjects(progressInfos[i], opts)
// returns slice of load.ProgressInfo, does not block, streamer is
// launched in goroutine
func StreamRemote(r remote.Remote, opts *remote.RemoteQueryOpts) *load.ProgressInfo {
progressInfo := &load.ProgressInfo{
ProgressChan: make(chan load.Progress),
ProjectsChan: make(chan []*projects.Project),
ErrorChan: make(chan error),
DoneChan: make(chan interface{}),
NumProjects: r.GetNumProjects(opts),
}
return progressInfos
go r.StreamProjects(progressInfo, opts)
return progressInfo
}
func NewRemotes() *Remotes {