in reply to Plack: Shutdown handler?

Perhaps a flexible strategy would be to create a thread-safe queue of subroutine-references.   When a signal is received, the signal-handler simply runs through this list, calling all of the routines on it in sequence.   Any number of routines can be executed, and the list can be reliably maintained through the use of off-the-shelf CPAN.

Replies are listed 'Best First'.
Re^2: Plack: Shutdown handler?
by jdrago999 (Pilgrim) on Aug 10, 2011 at 20:51 UTC

    Perhaps a flexible strategy would be to create a thread-safe queue of subroutine-references.

    I like the idea, but I'm curious if there is something built-in to Plack itself. Something along the lines of a mod_perl2 `PerlShutdownHandler` thing. I don't see anything in the Plack docs but maybe I'm just looking wrong.

      I would not expect Plack to have such a thing.   The signal (whatever it is...) comes in once, and you are just carrying-out one or more actions in response to it.   (Hardware interrupt service routines in operating-systems routinely adopt a similar strategy, made necessary in part by the “sharing” of a limited number of IRQs, and in part by there simply being a variable number of “interested listeners.”)

      Packages like POE do have some logic along these lines ... whether to be literally-used or to be studied as a possible example.   These are the basis for “reactive,” “event-driven” systems which would treat “shutdown request” as just another type of event that can happen.   Food for thought, maybe.