@@ -106,7 +106,6 @@ module.exports = Schema.extend({
106106 if ( success ) {
107107 success ( model , resp , options ) ;
108108 }
109- model . trigger ( 'sync' ) ;
110109 } ;
111110
112111 var start = new Date ( ) ;
@@ -159,6 +158,7 @@ module.exports = Schema.extend({
159158 'total analysis time' : totalTime - timeToFirstDoc ,
160159 'average analysis time per doc' : ( totalTime - timeToFirstDoc ) / sampleCount
161160 } ) ;
161+ model . trigger ( 'sync' ) ;
162162 options . success ( { } ) ;
163163 } ;
164164
@@ -174,8 +174,6 @@ module.exports = Schema.extend({
174174 return options . success ( { } ) ;
175175 }
176176
177- debug ( 'count' , count ) ;
178-
179177 var status = 0 ;
180178 var numSamples = Math . min ( options . size , count ) ;
181179 var stepSize = Math . ceil ( Math . max ( 1 , numSamples / 10 ) ) ;
@@ -193,7 +191,8 @@ module.exports = Schema.extend({
193191
194192 model . samplingStream
195193 . on ( 'error' , function ( sampleErr ) {
196- this . destroy ( ) ;
194+ model . samplingStream . destroy ( ) ;
195+ model . analyzingStream . destroy ( ) ;
197196 onFail ( sampleErr ) ;
198197 } )
199198 . pipe ( model . analyzingStream )
@@ -214,14 +213,10 @@ module.exports = Schema.extend({
214213 schemaStatusSubview . error = true ;
215214 onFail ( analysisErr ) ;
216215 } )
217- . on ( 'data ' , function ( ) {
218- if ( sampleCount > = numSamples ) {
216+ . on ( 'end ' , function ( ) {
217+ if ( sampleCount == = numSamples ) {
219218 return onEnd ( ) ;
220219 }
221- // workaround, as 'data' seems to be emitted even when sample stage
222- // has an error. @ChristianKvalheim investigating.
223- debug ( 'did not receive data from the driver.' ) ;
224- onFail ( new Error ( 'did not receive data from driver.' ) ) ;
225220 } ) ;
226221 } ) ;
227222 } ,
@@ -230,17 +225,13 @@ module.exports = Schema.extend({
230225 this . fetch ( ) ;
231226 } ,
232227 stopAnalyzing : function ( ) {
233- if ( ! this . is_fetching ) {
234- return ;
228+ if ( this . is_fetching ) {
229+ this . is_fetching = false ;
230+ this . samplingStream . destroy ( ) ;
231+ this . analyzingStream . destroy ( ) ;
235232 }
236- this . is_fetching = false ;
237- // @todo thomasr, uncomment this line once we figured out why
238- // app.client.sample() is not emitting any events anymore.
239- // for now, we can use app.client.find instead.
240-
241- // this.samplingStream.destroy();
242- this . analyzingStream . destroy ( ) ;
243233 app . statusbar . hide ( true ) ;
234+ this . trigger ( 'sync' ) ;
244235 } ,
245236 serialize : function ( ) {
246237 var res = this . getAttributes ( {
0 commit comments