Browse Source

move oncemore to own file

Gil Pedersen 13 years ago
parent
commit
e0cb5c0df7
2 changed files with 40 additions and 36 deletions
  1. 39 0
      lib/oncemore.js
  2. 1 36
      lib/reader.js

+ 39 - 0
lib/oncemore.js

@@ -0,0 +1,39 @@
+var util = require('util');
+
+module.exports = oncemore;
+
+// apply oncemore() to an emitter, and enable it to accept multiple events as input 
+function oncemore(emitter) {
+  if (!emitter) return emitter;
+
+  var once = emitter.once;
+  if (once && !once._old) {
+    emitter.once = function(type, listener) {
+      if (arguments.length <= 2)
+        return once.apply(this, arguments);
+
+      var types = Array.prototype.slice.call(arguments, 0, -1);
+      var listener = arguments.length ? arguments[arguments.length-1] : undefined;
+      if (typeof listener !== 'function')
+        throw TypeError('listener must be a function');
+
+      function g() {
+        types.forEach(function(type) {
+          this.removeListener(type, g);
+        }, this);
+
+        listener.apply(this, arguments);
+      }
+      g.listener = listener;
+
+      types.forEach(function(type) {
+        this.on(type, g);
+      }, this);
+
+      return this;
+    };
+    emitter.once._old = once;
+  }
+
+  return emitter;
+}

+ 1 - 36
lib/reader.js

@@ -6,6 +6,7 @@ var util = require('util'),
     assert = require('assert');
 
 var request = require('request'),
+    oncemore = require('./oncemore'),
     debug = require('debug')('hls:reader');
 
 try {
@@ -26,42 +27,6 @@ var DEFAULT_AGENT = util.format('hls-tools/v%s (http://github.com/kanongil/node-
 module.exports = hlsreader;
 hlsreader.HlsStreamReader = HlsStreamReader;
 
-// apply oncemore() to an emitter, and enable it to accept multiple events as input 
-function oncemore(emitter) {
-  if (!emitter) return emitter;
-
-  var once = emitter.once;
-  if (once && !once._old) {
-    emitter.once = function(type, listener) {
-      if (arguments.length <= 2)
-        return once.apply(this, arguments);
-
-      var types = Array.prototype.slice.call(arguments, 0, -1);
-      var listener = arguments.length ? arguments[arguments.length-1] : undefined;
-      if (typeof listener !== 'function')
-        throw TypeError('listener must be a function');
-
-      function g() {
-        types.forEach(function(type) {
-          this.removeListener(type, g);
-        }, this);
-
-        listener.apply(this, arguments);
-      }
-      g.listener = listener;
-
-      types.forEach(function(type) {
-        this.on(type, g);
-      }, this);
-
-      return this;
-    };
-    emitter.once._old = once;
-  }
-
-  return emitter;
-}
-
 /*
 options:
   startSeq*