MA> Ted Zlatanov <tzz@...> writes:
>> Maybe you can approach this similarly to url-future.el?
>> I intended to make it generic but only had use for the URL retrieval
>> case; you'll see it's easy to adapt it to be generic. Futures map well
>> to combinations of synchronous/asynchronous operations, in my
>> experience, and they can be chained.
MA> Maybe. Unfortunately, I don't understand how to use it, reading the
MA> source. Do you have an example which demonstrates its usage?
Sorry, I have done a bad job documenting it :) If the explanation below
is helpful, I'll change the docs in the file.
The idea is not new; Scheme has `delay' and `force' to do similar work.
It's a way to promise work but not necessarily use it immediately.
So let's make a future to promise the evaluation of 2+2:
(message "Future completion status before call: %s, value %s"
(message "Future completion status after call: %s, value %s"
This will print (with a debugger call you can `c' out of, in the callback):
Future completion status before call: nil, value (lambda nil (+ 2 2))
Future completion status after call: t, value 4
Replace (+ 2 2) with (+ 2 nil) in the value to see error handling.
Emacs Lisp doesn't have support for delayed evaluation, so this was a
way to work around that limitation and provide a generic interface. I
don't know if the language could support tighter integration with
delayed evaluations without core changes.
Futures can be cancelled in this implementation.
It's under url-future-* because we wanted to see how useful it would
prove before making it more prominent. If you find this approach
useful, let me know; if not and you think it could be useful with some
API or code changes then that's good to know as well.