Skip to content
This repository

utils.pause does not pause event #137

Closed
fxfred opened this Issue October 27, 2010 · 3 comments

2 participants

fxfred TJ Holowaychuk
fxfred

It seems that session is using utils.pause to pause the requests getting in to chain. But the "pause" does not remove existing listeners at all. So the existing listeners will still accept new events, and when pause.end/resume is called, the same events will be triggered twice.
There may be other side effects too.
Looks like a bug. Any idea?

TJ Holowaychuk
Collaborator

sounds like it could be a bug. would be nice if we had some test coverage for these

fxfred

If we can stop the store.get for a second, and send some data to the server in the mean while, we may can see the duplicated events.

I tried the following code.
(function() {
var connect, endofit, events, obj, pause, sys, util;
connect = require('connect');
util = connect.utils;
sys = require('sys');
events = require('events');
obj = new events.EventEmitter();
obj.on('data', function(data) {
return sys.print('data:' + data + '\n');
});
obj.on('end', function(data) {
return sys.print('end:' + data + '\n');
});
obj.emit('data', 'test data1');
pause = util.pause(obj);
obj.emit('data', 'test 222');
sys.print('after pause\n');
obj.emit('data', 'test 333');
endofit = function() {
pause.end();
sys.print('before resume\n');
return pause.resume();
};
setTimeout(endofit, 1000);
}).call(this);

Output is like this:

data:test data1
data:test 222
after pause
data:test 333
before resume
data:test 222
data:test 333

TJ Holowaychuk
Collaborator

yeah good call, we can test the util much easier than the implementation, ill try and get to this soonish

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.