jwiegley / emacs-async

Simple library for asynchronous processing in Emacs
GNU General Public License v3.0
832 stars 68 forks source link

Fix and clarify async-ready, async-get and async-wait (#71). #72

Closed thierryvolpiatto closed 7 years ago

thierryvolpiatto commented 7 years ago
thierryvolpiatto commented 7 years ago

@jwiegley Please verify I am not wrong in the return value of async-ready and also about making async-wait private.

Thanks.

jwiegley commented 7 years ago

async-wait is intended to be a user-facing function that returns when async-get would not block. Why did you want to make it private?

thierryvolpiatto commented 7 years ago

John Wiegley notifications@github.com writes:

async-wait is intended to be a user-facing function that returns when async-get would not block.

Ok, can you give some examples, perhaps in test file ?

Why did you want to make it private?

I had the impression it was only used internally, but was unsure about its usage, why I asked ;-).

Thanks.

-- Thierry

jwiegley commented 7 years ago

The example is simply this: If you call async-get, it will block until the future provides a value, and then return that value. If you call async-wait, it will also block until the future provides a value, but it does not return that value -- it leaves it unclaimed in the future. It provides a way to say, "I want to wait until the future is ready", without doing anything with that value.

thierryvolpiatto commented 7 years ago

John Wiegley notifications@github.com writes:

The example is simply this: If you call async-get, it will block until the future provides a value, and then return that value. If you call async-wait, it will also block until the future provides a value, but it does not return that value -- it leaves it unclaimed in the future. It provides a way to say, "I want to wait until the future is ready", without doing anything with that value.

Thanks for explanation.

However I think there is a bug here which makes an infloop in async-wait if user touch a key, you can reproduce with following code:

(let ((proc (async-start 
             (lambda () (sit-for 3) (message "hello") ))))
  (async-wait proc))

If you eval this code and touch nothing, it returns nil, ok, but if you hit a key before it finishes, it hangup forever.

A solution is using sleep-for in async-wait instead of sit-for.

WDYT?

-- Thierry

jwiegley commented 7 years ago

Sure, that sounds good to me.

thierryvolpiatto commented 7 years ago

John Wiegley notifications@github.com writes:

Merged #72.

Thanks, rebased and merged in ELPA.

-- Thierry