5 ms·
Saw something similar in Martini (golang): https://github.com/codegangsta/martini#next https://github.com/codegangsta/martini#next // log before and after
by Gigablah 13y ago
Saw something similar in Martini (golang):
https://github.com/codegangsta/martini#next https://github.com/codegangsta/martini#next
// log before and after a request
m.Use(func(c martini.Context, log *log.Logger){
log.Println("before a request")
c.Next()
log.Println("after a request")
})
- bjconlan 13y agoI don't think this yields the current thread/routine though does it? I think what you are seeing here is closer to express': function(req, res, next) { console.log('before'); next(); // go to the next middleware handler console.log('after the middleware stack has been traversed'); }
- andreypopp 13y agoI think does yield as stated in docs. Go have coroutines so there is no need in generators.
- flym4n 13y agoThat's using a callback, like express or connect does. What's new in koa is the use of js generators
- jerf 13y agoGo doesn't need JS generators. It already handles execution flow correctly. It is not correct to assume the Node execution model holds everywhere; we've made a lot of great advances since the old event-based model was invented in the 70s. That actually wraps the full handler without any need to jump through event threading hoops, and is not "blocking", in the sense that the Node community uses the term. That's an out-of-the-box feature for a modern language.
- klibertp 13y ago> That's an out-of-the-box feature for a modern language. Or for any Scheme for the last 30 years, but don't let that change your views on how "modern" you language is :)
- jerf 13y ago"Everything" was invented by the 70s (and a lot in the 60s); unfortunately the huge stinking popularity of GUIs combined with relentless drum beats of the latest code being due out yesterday took us on a decades-long detour through what turned out to be some bad ideas (OO in the "model the physical world" sense, which GUI frameworks deceptively made appear to work, event-based systems which are simple spaghetti-code redux in the Dijkstra sense of "spaghetti code").
- munificent 13y agoCompared to JavaScript, Scheme is a modern language!