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