Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compose.hook or similar #6

Open
tj opened this issue Dec 22, 2013 · 10 comments
Open

add compose.hook or similar #6

tj opened this issue Dec 22, 2013 · 10 comments

Comments

@tj
Copy link
Member

tj commented Dec 22, 2013

some API for extending externally, for example the new debug stuff I just added could live in a different module. I'd like to provide a nicer alternative that outputs HTML documents since the terminal quickly becomes a clusterfuck, especially with parallel requests

@mcwhittemore
Copy link

One thing I'm not sure about is what to call "events". The current debug code is using up and down but I'm not sure that is 100% clear to the end user. Client side talks about this as capturing and bubbling, but that doesn't seem right either. Is start and stop clear?

using on

var compose = require("koa-compse");

compose.on("down", function(ctx, name){ console.log(name, "has started"); });
compose.on("up", function(ctx, name){ console.log(name, "has finished"); });

using hook

var compose = require("koa-compse");

compose.hook(function(ctx, name, direction){
  if(direction=="down"){
    console.log(name, "has started");
  }
  else{
    console.log(name, "has finished");
  }
});

@tj
Copy link
Member Author

tj commented Mar 13, 2014

we could implement it as more middleware that get injected inbetween, so you'd just do a normal yield. it feels super dirty to do this at the compose level though, I'd almost rather remove this library and have it be a thing in Koa. There's no guarantee that people will use compose() to compose middleware so unless we make it a formal thing it seems awkward

@mcwhittemore
Copy link

I see the value of adding this to koa but how would koa inject debugging
into something like compose?

On Wed, Mar 12, 2014 at 9:59 PM, TJ Holowaychuk [email protected]:

we could implement it as more middleware that get injected inbetween, so
you'd just do a normal yield. it feels super dirty to do this at the
compose level though, I'd almost rather remove this library and have it
be a thing in Koa. There's no guarantee that people will use compose() to
compose middleware so unless we make it a formal thing it seems awkward

Reply to this email directly or view it on GitHubhttps://github.com//issues/6#issuecomment-37492228
.

@PlasmaPower
Copy link
Contributor

Implemented in #51 and #52

@PlasmaPower
Copy link
Contributor

Is there any consensus on this yet? I'd like to get an implementation merged.

@jonathanong jonathanong removed their assignment Aug 9, 2016
@PlasmaPower
Copy link
Contributor

With the Koa v2 release in sight, I'd like to get a wrapper implementation merged. How should I work towards this goal?

@fl0w
Copy link
Contributor

fl0w commented Jun 7, 2017

Is this still an open issue, or could there be consensus on the hope of node 8's experimental async_hook to rescue the situation soon enough?

@PlasmaPower
Copy link
Contributor

I think async_hook is more diagnostic oriented. While useful, I think wrappers will have other uses.

@fl0w
Copy link
Contributor

fl0w commented Jun 7, 2017

Heh, yea. To be fair, that was the only use case I had in mind anyway.

@bertho-zero
Copy link

bertho-zero commented Apr 7, 2021

There is @feathersjs/hooks which allows hooking any async function, based on koa-compose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants