lorniu / go-translate

Translator on Emacs. Supports multiple engines such as Google, Bing, deepL, ChatGPT, StarDict, Youdao and so on.
GNU General Public License v3.0
283 stars 38 forks source link

新建引擎时,在嵌套函数传递过程 task 释放了,该如何解决。 #58

Closed iT-Boyer closed 1 year ago

iT-Boyer commented 1 year ago
(cl-defmethod gts-claude-talk-lasttime ((engine gts-claude-engine) text done fail)
  (with-slots (talkurl auth-key channel) engine
    (setq turl (format talkurl channel (url-hexify-string text)))
    (gts-do-request turl
                    :headers `(("Authorization" . ,(format "Bearer %s" auth-key)))
                    :done done
                    :fail fail)
    ))

(cl-defmethod gts-translate ((engine gts-claude-engine) task rendercb)
  (gts-claude-talk-lasttime engine (oref task text)
                            (lambda ()
                              ;; (with-slots (text) task
                              ;; (message "对话内容:%s" (oref task text))
                              (goto-char (point-min))
                              (let ((time)
                                    (json-object-type 'plist)
                                    (json-array-type 'list))
                                (let ((json-data (json-read)))
                                  (setq time (plist-get json-data :ts))
                                  (message "传递时间戳00 :%s " time)
                                  (gts-update-raw task (buffer-string))
                                  (message "传递时间戳11 :%s " time)
                                  ;; (message " done --:%s " (oref engine talkurl))
                                  ;; (message "fail--:%s" turl)
                                  (subscribe-claude-request engine time (lambda ()
                                                                          (message "完成开始绘制 -- ")
                                                                          (gts-update-raw task (buffer-string))
                                                                          (gts-parse (oref engine parser) task)
                                                                          (funcall rendercb)
                                                                          )
                                                            ))))

                            (lambda (err)
                              (gts-render-fail task
                                (format "获取令牌密钥时出错,请检查您的网络和代理,或稍后重试\n\n%s" err)))))

gts-claude-talk-lasttime的闭包回调时,运行到这段代码提示 task 为nil

 (gts-update-raw task (buffer-string))
(message "传递时间戳11 :%s " time)

希望能帮忙分析下,是否存在语法的问题。