From 87c6832663b7e9a9612b04509e2201d4cd340313 Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Tue, 19 Mar 2024 13:27:49 +0800 Subject: [PATCH] prompt: Execute return result count (#22) --- prompt/prompt.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/prompt/prompt.go b/prompt/prompt.go index a022365..cd75943 100644 --- a/prompt/prompt.go +++ b/prompt/prompt.go @@ -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) @@ -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 }