Fix for issue #4 -- nested callbacks with same index key
This commit is contained in:
parent
591b563667
commit
2d8c851810
|
@ -0,0 +1,2 @@
|
||||||
|
dict
|
||||||
|
node_modules
|
|
@ -1,7 +1,7 @@
|
||||||
wordpos
|
wordpos
|
||||||
=======
|
=======
|
||||||
|
|
||||||
wordpos is a set of part-of-speech utilities for Node.js using [natural's](http://github.com/NaturalNode/natural) WordNet module.
|
wordpos is a set of part-of-speech (POS) utilities for Node.js using [natural's](http://github.com/NaturalNode/natural) WordNet module.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -353,4 +353,4 @@ License
|
||||||
|
|
||||||
(The MIT License)
|
(The MIT License)
|
||||||
|
|
||||||
Copyright (c) 2012, mooster@42at.com
|
Copyright (c) 2012, 2014 mooster@42at.com
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"author": "Moos <mooster@42at.com>",
|
"author": "Moos <mooster@42at.com>",
|
||||||
"keywords": ["natural", "language", "wordnet", "pos"],
|
"keywords": ["natural", "language", "wordnet", "pos"],
|
||||||
"description": "wordpos is a set of part-of-speech utilities for Node.js using natural's WordNet module.",
|
"description": "wordpos is a set of part-of-speech utilities for Node.js using natural's WordNet module.",
|
||||||
"version": "0.1.8",
|
"version": "0.1.9",
|
||||||
"homepage": "https://github.com/moos/wordpos",
|
"homepage": "https://github.com/moos/wordpos",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.6"
|
"node": ">=0.6"
|
||||||
|
|
|
@ -182,7 +182,6 @@ describe('options passed to constructor', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('profile option', function() {
|
describe('profile option', function() {
|
||||||
|
|
||||||
var wp = new WordPOS({profile : true});
|
var wp = new WordPOS({profile : true});
|
||||||
|
|
||||||
it('should return time argument for isX()', function(done){
|
it('should return time argument for isX()', function(done){
|
||||||
|
@ -223,5 +222,23 @@ describe('profile option', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('nested callbacks on same index key', function() {
|
||||||
|
var wp = new WordPOS(),
|
||||||
|
word1 = 'head',
|
||||||
|
word2 = word1 + 'er';
|
||||||
|
|
||||||
|
it('should call inner callback', function(done){
|
||||||
|
wp.getPOS(word1, function(result) {
|
||||||
|
expect(result.nouns[0]).toEqual(word1);
|
||||||
|
|
||||||
|
// inner call on word2
|
||||||
|
wp.getPOS(word2, function(result) {
|
||||||
|
expect(result.nouns[0]).toEqual(word2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function noop(){}
|
function noop(){}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ function loadFastIndex(dir, name) {
|
||||||
data = JSON.parse( fs.readFileSync(jsonFile,'utf8') );
|
data = JSON.parse( fs.readFileSync(jsonFile,'utf8') );
|
||||||
//console.log('loaded %d buckets for %s', data.stats.buckets, data.name);
|
//console.log('loaded %d buckets for %s', data.stats.buckets, data.name);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error('Error with fast index file %s\n ', jsonFile, e);
|
console.error('Error with fast index file. Try reinstalling from npm!');
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +95,13 @@ function find(search, callback) {
|
||||||
return line.substring(0,line.indexOf(' '));
|
return line.substring(0,line.indexOf(' '));
|
||||||
});
|
});
|
||||||
|
|
||||||
readCallbacks[key].forEach( test );
|
// live access callbacks cache in case nested cb's
|
||||||
|
// add to the array.
|
||||||
|
while (readCallbacks[key].length) {
|
||||||
|
test(readCallbacks[key].shift());
|
||||||
|
}
|
||||||
|
|
||||||
|
// now done - delete cb cache
|
||||||
delete readCallbacks[key];
|
delete readCallbacks[key];
|
||||||
|
|
||||||
if (--self.refcount == 0) {
|
if (--self.refcount == 0) {
|
||||||
|
|
Loading…
Reference in New Issue