ah, good that is what I thought.

I did this with my assertion framework, macgyver, i attempted this twice,
about 9 months apart. the second time it worked.

https://github.com/dominictarr/macgyver/blob/master/index.js

basically, my approach is to wrap a target function in a new function
that manages a list of actions that may trigger before, after, or
around (which could possibly catch errors)

in the first attempt each hook wrapped a new closure around the
target. this was fail because i lost track of the identity of the
target function, and it was not possible to remove hooks.

sync hooks where sufficant for my purposes with macgyver, but with
async the basic pattern would be the same.

On Tue, Jul 31, 2012 at 7:33 PM, Bradley Meck <[email protected]> wrote:
> I mean to say that a plugin or dependency injection of some kind be able to
> do something before the main process does anything.
>
>
> On Tuesday, July 31, 2012 11:22:23 AM UTC-5, Dominic wrote:
>>
>> I don't quite understand the intension of the code you posted.
>>
>> do you mean to be able to have methods that you can add plugins to
>> that get called
>> before or after a main process does something? so that you can do
>> extra stuff when an event occurs? or do you mean to delay an event?
>>
>> On Wed, Aug 1, 2012 at 4:02 AM, Bradley Meck <[email protected]>
>> wrote:
>> > Wondering what everyone is doing for hookable events these days. I am
>> > looking to use something that lets me do similar to emitHook(ee, event,
>> > arg1, after(err)), I am wondering what other people are doing, or if
>> > they
>> > are using something instead of event emitters to share state for
>> > hookable
>> > events. I could use my own implementation but would rather follow an
>> > established pattern if there is any.
>> >
>> > ```
>> > function emitHook(ee, event, /*...,*/ callback) {
>> >   var args = [].slice.call(arguments, 1, -1);
>> >   var defers = 0;
>> >   function defer(hook) {
>> >     defers++;
>> >     hook(finish);
>> >   }
>> >   function finish(err) {
>> >     if (err) {
>> >       defers = 0;
>> >     }
>> >     defers--;
>> >     if (defers === 0) {
>> >       callback(err);
>> >     }
>> >   }
>> >   if (defers === 0) {
>> >     callback();
>> >   }
>> >   return ee.emit.apply(ee, args.concat(defer));
>> > }
>> > ```
>> >
>> > --
>> > Job Board: http://jobs.nodejs.org/
>> > Posting guidelines:
>> > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> > You received this message because you are subscribed to the Google
>> > Groups "nodejs" group.
>> > To post to this group, send email to [email protected]
>> > To unsubscribe from this group, send email to
>> > [email protected]
>> > For more options, visit this group at
>> > http://groups.google.com/group/nodejs?hl=en?hl=en
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to