librelist archives

« back to archive

Re: [leiningen] Hook/middleware lifecycle

Re: [leiningen] Hook/middleware lifecycle

From:
Phil Hagelberg
Date:
2013-08-20 @ 18:10
Julien Eluard writes:

> I'm playing with some dumb plugins and noticed both middleware/hook can be
> called several times depending on the leiningen task executed.
>
> Any pointer documenting middleware/hook lifecycle?
> Are they expected to be idempotent?

Middleware and hooks will get called every time the project map is
calculated. This happens when Leiningen is first launched, but it will
happen again if a new set of profiles are applied. But in general
just the return value of middleware functions should be what matters. If
you do put side-effects in middleware they should be idempotent.

Calls to `add-hook` will be idempotent if you specify them as vars;
unfortunately bare fns are not comparable for equality in clojure, so
add-hook calls that use them can't be idempotent. This could result in
hooks being double-wrapped in cases where the project map must be
re-calculated.

The problem is that different profiles could declare different hooks and
middleware, so just running the ones from the default profiles won't do.

I'll clarify this in doc/PLUGINS.md.

-Phil

Re: [leiningen] Hook/middleware lifecycle

From:
Julien Eluard
Date:
2013-08-20 @ 19:15
Thanks, that's much clearer now.

Julien


2013/8/20 Phil Hagelberg <phil@hagelb.org>

>
> Julien Eluard writes:
>
> > I'm playing with some dumb plugins and noticed both middleware/hook can
> be
> > called several times depending on the leiningen task executed.
> >
> > Any pointer documenting middleware/hook lifecycle?
> > Are they expected to be idempotent?
>
> Middleware and hooks will get called every time the project map is
> calculated. This happens when Leiningen is first launched, but it will
> happen again if a new set of profiles are applied. But in general
> just the return value of middleware functions should be what matters. If
> you do put side-effects in middleware they should be idempotent.
>
> Calls to `add-hook` will be idempotent if you specify them as vars;
> unfortunately bare fns are not comparable for equality in clojure, so
> add-hook calls that use them can't be idempotent. This could result in
> hooks being double-wrapped in cases where the project map must be
> re-calculated.
>
> The problem is that different profiles could declare different hooks and
> middleware, so just running the ones from the default profiles won't do.
>
> I'll clarify this in doc/PLUGINS.md.
>
> -Phil
>