Skip to content

Commit

Permalink
prompt: Execute return result count (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshineplan committed Mar 19, 2024
1 parent a0e3fd9 commit 87c6832
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ type Result struct {
Error error
}

func (prompt *Prompt) Execute(ai ai.AI, input []string, prefix string) (<-chan Result, error) {
func (prompt *Prompt) Execute(ai ai.AI, input []string, prefix string) (<-chan Result, int, error) {
prompts, err := prompt.execute(input, prefix)
if err != nil {
return nil, err
return nil, 0, err
}
c := make(chan Result, len(prompts))
n := len(prompts)
c := make(chan Result, n)
go func() {
workers.RunSlice(prompt.workers, prompts, func(i int, p string) {
ctx, cancel := context.WithTimeout(context.Background(), prompt.d)
Expand All @@ -141,5 +142,5 @@ func (prompt *Prompt) Execute(ai ai.AI, input []string, prefix string) (<-chan R
})
close(c)
}()
return c, nil
return c, n, nil
}

0 comments on commit 87c6832

Please sign in to comment.