Skip to content

Commit

Permalink
Merge pull request #72 from jwiegley/Fix_async_ready
Browse files Browse the repository at this point in the history
Fix and clarify async-ready, async-get and async-wait (#71).
  • Loading branch information
jwiegley authored Feb 19, 2017
2 parents 54977d6 + d1273c8 commit 666066d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions async.el
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,32 @@ as follows:
(prin1 (list 'async-signal err)))))))

(defun async-ready (future)
"Query a FUTURE to see if the ready is ready -- i.e., if no blocking
"Query a FUTURE to see if it is ready.
I.e., if no blocking
would result from a call to `async-get' on that FUTURE."
(and (memq (process-status future) '(exit signal))
(with-current-buffer (process-buffer future)
async-callback-value-set)))
(let ((buf (process-buffer future)))
(if (buffer-live-p buf)
(with-current-buffer buf
async-callback-value-set)
t))))

(defun async-wait (future)
"Wait for FUTURE to become ready."
(while (not (async-ready future))
(sit-for 0.05)))
(sleep-for 0.05)))

(defun async-get (future)
"Get the value from an asynchronously function when it is ready.
"Get the value from process FUTURE when it is ready.
FUTURE is returned by `async-start' or `async-start-process' when
its FINISH-FUNC is nil."
(async-wait future)
(with-current-buffer (process-buffer future)
(async-handle-result #'identity async-callback-value (current-buffer))))
(and future (async-wait future))
(let ((buf (process-buffer future)))
(when (buffer-live-p buf)
(with-current-buffer buf
(async-handle-result
#'identity async-callback-value (current-buffer))))))

(defun async-message-p (value)
"Return true of VALUE is an async.el message packet."
Expand Down

0 comments on commit 666066d

Please sign in to comment.