mirror of
				https://github.com/TeamPiped/instances-api.git
				synced 2024-08-14 23:57:19 +00:00 
			
		
		
		
	Store checked instances in map to preserve order.
This commit is contained in:
		
							parent
							
								
									e8d2b2b267
								
							
						
					
					
						commit
						20e5350736
					
				
					 1 changed files with 15 additions and 4 deletions
				
			
		
							
								
								
									
										19
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								main.go
									
										
									
									
									
								
							| 
						 | 
					@ -238,11 +238,12 @@ func monitorInstances() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			lines := strings.Split(buf.String(), "\n")
 | 
								lines := strings.Split(buf.String(), "\n")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var instances []Instance
 | 
								instancesMap := make(map[int]Instance)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			wg := sync.WaitGroup{}
 | 
								wg := sync.WaitGroup{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			skipped := 0
 | 
								skipped := 0
 | 
				
			||||||
 | 
								checking := 0
 | 
				
			||||||
			for _, line := range lines {
 | 
								for _, line := range lines {
 | 
				
			||||||
				split := strings.Split(line, "|")
 | 
									split := strings.Split(line, "|")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -257,18 +258,28 @@ func monitorInstances() {
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				wg.Add(1)
 | 
									wg.Add(1)
 | 
				
			||||||
				go func(split []string) {
 | 
									go func(i int, split []string) {
 | 
				
			||||||
					defer wg.Done()
 | 
										defer wg.Done()
 | 
				
			||||||
					instance, err := getInstanceDetails(split, latest)
 | 
										instance, err := getInstanceDetails(split, latest)
 | 
				
			||||||
					if err == nil {
 | 
										if err == nil {
 | 
				
			||||||
						instances = append(instances, instance)
 | 
											instancesMap[i] = instance
 | 
				
			||||||
					} else {
 | 
										} else {
 | 
				
			||||||
						log.Print(err)
 | 
											log.Print(err)
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}(split)
 | 
									}(checking, split)
 | 
				
			||||||
 | 
									checking++
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			wg.Wait()
 | 
								wg.Wait()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Map to ordered array
 | 
				
			||||||
 | 
								var instances []Instance
 | 
				
			||||||
 | 
								for i := 0; i < checking; i++ {
 | 
				
			||||||
 | 
									instance, ok := instancesMap[i]
 | 
				
			||||||
 | 
									if ok {
 | 
				
			||||||
 | 
										instances = append(instances, instance)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// update the global instances variable
 | 
								// update the global instances variable
 | 
				
			||||||
			monitored_instances = instances
 | 
								monitored_instances = instances
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue