Skip to content

Commit f69979a

Browse files
authored
Merge pull request #67 from nodo-digital/fix-stream-support
Fix stream support
2 parents 5eef328 + 42fcae8 commit f69979a

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

dist/longjohn.js

Lines changed: 15 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/longjohn.coffee

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,25 @@ EventEmitter.prototype.addListener = (event, callback) ->
154154

155155
EventEmitter.prototype.on = (event, callback) ->
156156
args = Array::slice.call(arguments)
157-
args[1] = wrap_callback(callback, 'EventEmitter.on')
158-
_on.apply(this, args)
159157

160-
EventEmitter.prototype.once = (event, callback) ->
161-
args = Array::slice.call(arguments)
162-
if typeof callback != 'function'
163-
throw TypeError('callback must be a function');
164-
fired = false
165-
wrap = wrap_callback(callback, 'EventEmitter.once');
166-
g = () ->
167-
this.removeListener(event, g)
168-
if !fired
169-
fired = true
170-
wrap.apply(this, arguments)
171-
g.listener = callback
158+
# Coming from EventEmitter.prototype.once
159+
if callback.listener
160+
wrap = wrap_callback(callback.listener, 'EventEmitter.once');
161+
162+
g = () ->
163+
this.removeListener(event, g)
164+
165+
if !fired
166+
fired = true
167+
wrap.apply(this, arguments)
168+
169+
g.listener = callback.listener;
170+
else
171+
g = wrap_callback(callback, 'EventEmitter.on')
172+
172173
args[1] = g;
174+
173175
_on.apply(this, args)
174-
return this;
175176

176177
EventEmitter.prototype.listeners = (event) ->
177178
listeners = _listeners.call(this, event)

test/test-longjohn.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,13 @@ describe 'longjohn', ->
168168
clearImmediate(immediate_id)
169169
done()
170170
, 1, 2, 3
171+
172+
it 'once should call overriden on', (done) ->
173+
Transform = require('stream').Transform
174+
175+
emitter = new Transform()
176+
177+
emitter.once('data', () -> )
178+
emitter.once('end', done)
179+
180+
emitter.push(null)

0 commit comments

Comments
 (0)