* Wait for function to execute?
@ 2017-06-08 21:34 Nikolay Kudryavtsev
2017-06-09 1:40 ` Emanuel Berg
0 siblings, 1 reply; 2+ messages in thread
From: Nikolay Kudryavtsev @ 2017-06-08 21:34 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
Hello.
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. So, when A runs, B runs too, eventually... Since it's a
unit test, changing B is off limits.
So far I'm thinking of advising B using advice-once described by Drew
here <https://emacs.stackexchange.com/a/26260/9143>. As my advice
function I would use a closure that wraps over some condition. Then I
would have a while loop that sleeps until that condition is fulfilled.
All this wrapped into one beautiful(ha!) macro. Are there any more, ugh,
reasonable options?
--
Best Regards,
Nikolay Kudryavtsev
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Wait for function to execute?
2017-06-08 21:34 Wait for function to execute? Nikolay Kudryavtsev
@ 2017-06-09 1:40 ` Emanuel Berg
0 siblings, 0 replies; 2+ messages in thread
From: Emanuel Berg @ 2017-06-09 1:40 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-06-09 1:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-08 21:34 Wait for function to execute? Nikolay Kudryavtsev
2017-06-09 1:40 ` Emanuel Berg
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).