 module.exports = (knex, callback) ->
 	count = 0
+	total = 0
 	after = null
 
 	next = ->

	callback
		_inject: (obj) ->
			count++

			t = obj.then
			obj.then = (callback) ->

		# Called after all queries have executed
		after: (callback) ->
			after = callback

			# Protect against queries having already all executed
			callback() if total > 0 and count is 0

			return
