summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js')
-rw-r--r--deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js b/deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js
new file mode 100644
index 0000000000..2aa7c05c58
--- /dev/null
+++ b/deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/are-we-there-yet/test/lib/test-event.js
@@ -0,0 +1,29 @@
+'use strict'
+var util = require('util')
+
+module.exports = function (obj, event, next) {
+ var timeout = setTimeout(gotTimeout, 10)
+ obj.once(event, gotResult)
+
+ function gotTimeout () {
+ obj.removeListener(event, gotResult)
+ next(new Error('Timeout listening for ' + event))
+ }
+ var result = []
+ function gotResult () {
+ result = Array.prototype.slice.call(arguments)
+ clearTimeout(timeout)
+ timeout = setTimeout(gotNoMoreResults, 10)
+ obj.once(event, gotTooManyResults)
+ }
+ function gotNoMoreResults () {
+ obj.removeListener(event, gotTooManyResults)
+ var args = [null].concat(result)
+ next.apply(null, args)
+ }
+ function gotTooManyResults () {
+ var secondResult = Array.prototype.slice.call(arguments)
+ clearTimeout(timeout)
+ next(new Error('Got too many results, first ' + util.inspect(result) + ' and then ' + util.inspect(secondResult)))
+ }
+}