branch: externals/llm commit 131a7ee5d304d52ae5641017883dc88bc055a39a Author: Andrew Hyatt <ahy...@gmail.com> Commit: Andrew Hyatt <ahy...@gmail.com>
Solve flaky errors when using sync llm commands The solution was to hold the mutexes every time we're changing the closure state. --- llm.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/llm.el b/llm.el index d9468ceaba..29e907a093 100644 --- a/llm.el +++ b/llm.el @@ -76,16 +76,20 @@ error callback. This will block until the async function calls one of the callbacks. The return value will be the value passed into the success callback." - (let ((cv (make-condition-variable (make-mutex "llm-chat-response"))) - (response)) + (let* ((mutex (make-mutex "llm-chat-response")) + (cv (make-condition-variable mutex)) + (response)) (apply f (append args (list (lambda (result) - (setq response result) - (condition-notify cv)) + (with-mutex mutex + (setq response result) + (condition-notify cv))) (lambda (type msg) - (signal type msg) - (condition-notify cv))))) + (with-mutex mutex + (message "async to sync, got error") + (signal type msg) + (condition-notify cv)))))) response)) (cl-defgeneric llm-chat-response (provider prompt)