FetchDescriptionsConcurrent fetches descriptions with bounded concurrency.
(client *api.Client, host, owner, repo string, skills []Skill, onProgress func(done, total int))
| 662 | |
| 663 | // FetchDescriptionsConcurrent fetches descriptions with bounded concurrency. |
| 664 | func FetchDescriptionsConcurrent(client *api.Client, host, owner, repo string, skills []Skill, onProgress func(done, total int)) { |
| 665 | total := 0 |
| 666 | for _, s := range skills { |
| 667 | if s.Description == "" { |
| 668 | total++ |
| 669 | } |
| 670 | } |
| 671 | if total == 0 { |
| 672 | return |
| 673 | } |
| 674 | |
| 675 | const maxWorkers = 10 |
| 676 | var wg sync.WaitGroup |
| 677 | var done atomic.Int32 |
| 678 | |
| 679 | jobs := make(chan *Skill) |
| 680 | |
| 681 | workers := min(maxWorkers, total) |
| 682 | for range workers { |
| 683 | wg.Go(func() { |
| 684 | for s := range jobs { |
| 685 | s.Description = fetchDescription(client, host, owner, repo, s) |
| 686 | |
| 687 | d := int(done.Add(1)) |
| 688 | if onProgress != nil { |
| 689 | onProgress(d, total) |
| 690 | } |
| 691 | } |
| 692 | }) |
| 693 | } |
| 694 | |
| 695 | for i := range skills { |
| 696 | if skills[i].Description == "" { |
| 697 | jobs <- &skills[i] |
| 698 | } |
| 699 | } |
| 700 | close(jobs) |
| 701 | wg.Wait() |
| 702 | } |
| 703 | |
| 704 | // DiscoverSkillByPathOptions controls optional behavior for DiscoverSkillByPathWithOptions. |
| 705 | type DiscoverSkillByPathOptions struct { |