文档说with-timeout
宏只能等待它在内部执行的代码“是可以等待的原语”。有没有这种原始的例子?
更多信息:我遇到了一种情况,我必须从一个对 TCP 服务器进行异步调用的函数返回结果。因此,如果您知道如何使此调用同步,那也会有所帮助。
不幸的是,我不能选择让它同步——这是一个由自动完成库调用的回调,它必须返回值。以下是尝试执行此操作的代码:
(defun haxe-ac-init ()
(unless (get-process haxe-compiler-process)
(haxe-connector-sentinel nil nil))
(let ((ac-request
(haxe-build-compile-string
(haxe-package) (buffer-file-name))))
(save-buffer)
(setq haxe-last-ac-candidates nil)
(process-send-string haxe-compiler-process ac-request)
(process-send-string haxe-compiler-process "\0")
(process-send-eof haxe-compiler-process))
(haxe-log 3 "haxe-ac-init sent request.")
(with-local-quit
(with-timeout (3 (haxe-log 0 "Compiler is too slow..."))
(block x ;; this while sometimes will loop forever
(while (equal (process-status (get-process haxe-compiler-process)) 'open)
(when (and last-compiler-response (= received-status 2))
(haxe-parse-ac-response last-compiler-response)
(throw 'x haxe-last-ac-candidates)))))))