I'm not sure this is the best way of tackling things. Thinking of the
process (in the broader sense of the term) that leads to creating the
response to a requests is a very limiting perspective. And I fail to
see a critical advantage. Being able to do
`require('kolba').getCurrentRequest();` ain't it. All other problems
that domains may introduce, it's smells like a recipe for high
coupling.
Rather than throwing ideas from multi-threaded synchronous programming
at the problem, I suggest using something that requires no fancy
tricks: basic OOP.
1. The code that handles a single request is bundled in an object
instantiated only for the purpose of handling that very request (you
could potentially pool those for reuse, but that's more of a
performance optimization). The request handler code accesses the
request as `this.request` and can store all other state specific to
handling that request in the `this` scope.
Such request handlers can exist in the same domain and communicate
with one another if necessary (prioritization, synchronization, direct
communication between two long polls etc.).
2. Follow `Tell, Don't Ask`. Rather than querying the global namespace
for some state, why is the request not passed in as a parameter? If
the whole thing needs to be passed in at all. You should build code
that consumes a minimal interface (you rarely need the full request,
often just the query information or just the upstream) and does
something useful with it. You can build the awesomest ever
functionality - if it's built against
`require('kolba').getCurrentRequest();` and I cannot or don't want to
use Kolba for some reason or another, I cannot use it.
This is is a sketch of how things could look like:
https://gist.github.com/back2dos/6376645
Such an approach can run on top of an arbitrary router.
And theoretically you can build all sorts of fancy stuff that spits
out complex handlers with error handling and what not from very little
input (say mongoose schema object + some ACL rule). That can be
plugged into such a router. But it needn't. People can still build
handlers from scratch or register raw handlers with the underlying
router. Composition FTW!!!
Regards,
Juraj
--
--
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
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.