Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible race condition if setup of event listeners is delayed? #14

Open
bpow opened this issue May 15, 2018 · 0 comments
Open

possible race condition if setup of event listeners is delayed? #14

bpow opened this issue May 15, 2018 · 0 comments

Comments

@bpow
Copy link

bpow commented May 15, 2018

I may just not be used to node/javascript idioms, but I think there is a race condition since there is no way to make sure that the event listeners are set up before events start getting triggered.

For instance, something like the following:

var VCF = require('./lib/index')

var allFeatures = []

var v = VCF.read('test/sample.vcf')

setTimeout(function () {
  v.on('data', (f) => allFeatures.push(f))
  v.on('end', () => console.log(allFeatures))
}, 1000)

will not write out any data because the vcf object emits all of its 'data' events before the 'data' listener is setup. But if the delay parameter (1000) is changed to '0', then the 'data' and 'end' listeners are setup in time.

I don't know if this is a problem in the real-world (if the .on('data'... directly follows the .read call, then maybe there is no way for the race to occur?)

Apologies if I just mis-understand the idiom.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant