--
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 nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
1. Event listeners
2. Callbacks passed from one JavaScript function to another.
3. Stuff waiting on something to happen from a lower level (libeio or
libev, or in the future, libuv.)
The EventEmitter stuff is all in JavaScript. For instance:
f = new EventEmitter
f.on("foo", function () { console.error("bar") })
f.emit("foo")
This never touches the event loop. It just adds the function object
to a list marked "foo", and then executes all the functions in that
list when you emit("foo"). (It's a little more involved than that for
API friendliness and performance, but not much.)
Callbacks passed from one bit of JavaScript to another is also pure-js
stuff. The difference between an "event handler" and a "callback" is
that typically callbacks are only ever called once, whereas an event
might be emitted many times. While callbacks typically are used
because there's some async operation which dips below the JS layer,
there's nothing stopping you from writing something like this:
function callRightNow (x, y, cb) {
cb(null, x + y)
}
When something has to do some IO (or sets a timer with setInterval,
setTimeout, or process.nextTick), it gets attached to the event loop.
It's not quite as straightforward as a 1:1 mapping from setTimeout
call to event loop timer. (That would be inefficient.)
When you do this:
net.createServer(reqHandler).listen(8000)
there's actually just one "thing" on the event loop: the function that
gets called whenever a new incoming TCP connection is initiated.
If you're interested in diving into the internals, it's pretty
fascinating. I'd start with src/node.cc and follow the trail.
src/node_file.cc is pretty straightforward if you're familiar with the
standard posix filesystem C functions. All the thread pool and event
loop stuff is in deps/eio and deps/ev (or deps/uv in master).