help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wait for function to execute?


From: Emanuel Berg
Subject: Re: Wait for function to execute?
Date: Fri, 09 Jun 2017 03:40:25 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Nikolay Kudryavtsev wrote:

> I have a case where I'm writing a unit
> test(A) that needs to wait for a function(B)
> that's called by a process sentinel for
> a process started by this unit test.

Do you want to child/subprocess Emacs or are
you thinking in the "lines" of
Lisp parallelism?

> So, when A runs, B runs too, eventually...
> Since it's a unit test, changing B is
> off limits.

Here is a simple demo. No parallelism or IPC to
it tho.

(defun add (n &rest r)
  (apply #'+ n r)
  ; 1 ;; uncomment this, re-eval to make add fail unit test
  )

(defun test-add (&rest _unused)
  (advice-remove 'add #'test-add)
  (when (= 6 (add 1 2 3))
    (advice-add 'add :before-while #'test-add)
    t) )

(advice-add 'add :before-while #'test-add)

(add 1 2 3 4 5) ; 15 on OK, nil on failure

> Then I would have a while loop that sleeps
> until that condition is fulfilled.

So called busy-wait. Should be avoided
according to the sacred scrolls. However the
simplest kind of semaphore implements it.
And when you call it that, it sounds
better already.

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

[Prev in Thread] Current Thread [Next in Thread]