all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <moasen@zoho.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Wait for function to execute?
Date: Fri, 09 Jun 2017 03:40:25 +0200	[thread overview]
Message-ID: <yw.86fufaey5y.fsf@zoho.com> (raw)
In-Reply-To: a4aac7df-74f1-c962-a925-7254e83940f2@gmail.com

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	other threads:[~2017-06-09  1:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-08 21:34 Wait for function to execute? Nikolay Kudryavtsev
2017-06-09  1:40 ` Emanuel Berg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw.86fufaey5y.fsf@zoho.com \
    --to=moasen@zoho.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.