Permalink
Browse files

Clean up early-lifetime events (stat/ready)

  • Loading branch information...
1 parent 1c00618 commit 10b0cac319dbaf6d870e2b5c71d26355e643d8f6 @isaacs isaacs committed Mar 27, 2012
Showing with 22 additions and 10 deletions.
  1. +5 −1 lib/dir-reader.js
  2. +17 −9 lib/reader.js
View
6 lib/dir-reader.js
@@ -130,7 +130,11 @@ DirReader.prototype._read = function () {
})
entry.on("stat", function (props) {
- me.emit("entryStat", entry, props)
+ me.emit("_entryStat", entry, props)
+ if (entry._aborted) return
+ if (entry._paused) entry.once("resume", function () {
+ me.emit("entryStat", entry, props)
+ })
})
entry.on("ready", function EMITCHILD () {
View
26 lib/reader.js
@@ -200,17 +200,25 @@ Reader.prototype._stat = function (currentStat) {
}
// last chance to abort or disown before the flow starts!
- me.emit("stat", props)
- if (me._aborted) {
- me.emit("end")
- me.emit("close")
- return
- }
+ var events = ["_stat", "stat", "ready"]
+ var e = 0
+ ;(function go () {
+ if (me._aborted) {
+ me.emit("end")
+ me.emit("close")
+ return
+ }
- me.emit("ready", props)
+ if (me._paused) {
+ me.once("resume", go)
+ return
+ }
- // if it's a directory, then we'll be emitting "entry" events.
- if (!me._paused) me._read()
+ var ev = events[e ++]
+ if (!ev) return me._read()
+ me.emit(ev, props)
+ go()
+ })()
}
}

0 comments on commit 10b0cac

Please sign in to comment.