 # Error-handling middleware are only called if a previous middleware threw or
 # passed an error. Conversely, non-error-handling middleware are skipped if a
 # previous error occurred.
-exports.Middleware = class Middleware
+exports.Middleware = class Middleware extends EventEmitter
 
 	# ## *constructor*
 	#

		# Kick things off.
		invoke()

# ## fromHook
#
# Create a middleware stack from the results of a hook and path configuration.
exports.fromHook = (hook, paths, args...) ->

	middleware = new Middleware

	# Invoke the hook and `use` the middleware in the paths configuration
	# order.

	#   finished. If an error occurred, it will be passed as the first
	#   argument.
	dispatch: (args..., fn) ->
		self = this

		index = 0

		invoke = (error) ->

			self.emit 'invoked', self._middleware[index - 1] if index > 0

			# Call `fn` with any error if we're done.
			return fn error if index is self._middleware.length

			current = self._middleware[index++]

			# Error-handling middleware.
			if current.length is args.length + 2
