@@ -48,18 +48,16 @@ CodeComplete.prototype.addHandler = function(name, handler) {
4848CodeComplete . prototype . addIndex = function ( name , populate , options ) {
4949 var that = this ;
5050 var index = null ;
51- var _isPopulating = false ;
51+ var inProgress = null ;
5252
5353 options = _ . defaults ( { } , options || { } , {
54- 'interval' : 1 * 60 * 1000 // 1 minute
54+ 'interval' : 60 * 1000 //1min
5555 } )
5656
5757 var populateIndex = function ( ) {
58- if ( _isPopulating ) {
59- return Q . reject ( new Error ( name + ": Already working on populating the index" ) ) ;
60- }
61- _isPopulating = true ;
62- return Q ( populate ( {
58+ if ( inProgress ) return inProgress ;
59+
60+ inProgress = Q ( populate ( {
6361 'root' : that . workspace . root ,
6462 'project' : that . project
6563 } ) ) . then ( function ( items ) {
@@ -68,8 +66,10 @@ CodeComplete.prototype.addIndex = function(name, populate, options) {
6866 index = null ;
6967 return Q . reject ( err ) ;
7068 } ) . fin ( function ( ) {
71- _isPopulating = false ;
72- } )
69+ inProgress = null ;
70+ } ) ;
71+
72+ return inProgress ;
7373 } ;
7474
7575 // Populate the index when there are changes
@@ -83,11 +83,14 @@ CodeComplete.prototype.addIndex = function(name, populate, options) {
8383 this . addHandler ( name , function ( options ) {
8484 var prepare = Q ( ) ;
8585
86- // if no ndex yet: populate the index
86+ // if no index yet: populate the index
8787 if ( ! index ) {
8888 prepare = populateIndex ( ) ;
8989 }
9090
91+ // If processing new data, wait for new update
92+ if ( inProgress ) prepare = inProgress ;
93+
9194 // Filter the index for getting the results
9295 return prepare . then ( function ( ) {
9396 // Filter is done by the 'get'
0 commit comments