unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Waiting for a condition
@ 2006-06-02 11:00 spamfilteraccount
  2006-06-05  6:19 ` spamfilteraccount
  0 siblings, 1 reply; 2+ messages in thread
From: spamfilteraccount @ 2006-06-02 11:00 UTC (permalink / raw)


I have a code where I'd like to perform an asynchronous operation and
then wait for the result of the operation synchronously in place. When
the operation is finished it calls a function, so I can do a signalling
there. If the operation was successful then the synchronous code should
continue, otherwise it should abort.

I came up with this solution which works, but inelegant imho:

  ...
  (let ((timeout 5))
    (while (and (not condition)
                (> timeout 0)
                (message (format "Waiting for condition... (%s)"
timeout))
                (sit-for 1))
      (decf timeout)))
  (unless condition
    (error "nope!")))
  ...

Is there a way to yield the execution here and wake it up when the
operation is finished (with timeout), without having to poll the
condition? I know sit-for returns is input is available. Should I
generate some kind of dummy event to wake sit-for up? But what event?
Mouse move?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Waiting for a condition
  2006-06-02 11:00 Waiting for a condition spamfilteraccount
@ 2006-06-05  6:19 ` spamfilteraccount
  0 siblings, 0 replies; 2+ messages in thread
From: spamfilteraccount @ 2006-06-05  6:19 UTC (permalink / raw)


spamfilteraccount@gmail.com wrote:
>
> Is there a way to yield the execution here and wake it up when the
> operation is finished (with timeout), without having to poll the
> condition? I know sit-for returns is input is available. Should I
> generate some kind of dummy event to wake sit-for up? But what event?
> Mouse move?

I thought this question was trivial and someone could answer it right
away. Is it not possible to do it in emacs?

I can generate an input event, but then I think that event should be
consumed by someone and it should not affect the user experience, so it
may not be rivial.

Or am I using the wrong approach and there is an other mechanism which
is more suitable here than sit-for?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-06-05  6:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-02 11:00 Waiting for a condition spamfilteraccount
2006-06-05  6:19 ` spamfilteraccount

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).