File tree 2 files changed +17
-40
lines changed
2 files changed +17
-40
lines changed Original file line number Diff line number Diff line change @@ -423,29 +423,22 @@ Base.prototype.run = function run(cb) {
423
423
debug ( 'Running ' + methodName ) ;
424
424
self . emit ( 'method:' + methodName ) ;
425
425
426
- runAsync (
427
- function ( ) {
428
- self . async = function ( ) {
429
- return this . async ( ) ;
430
- } . bind ( this ) ;
431
-
432
- return method . apply ( self , self . args ) ;
433
- } ,
434
- // runAsync return a promise which wraps first function.
435
- // So ensure the callback function never throw an error.
436
- function ( err ) {
437
- if ( err ) {
438
- debug ( 'An error occured while running ' + methodName , err ) ;
439
- if ( self . listeners ( 'error' ) . length > 0 ) {
440
- self . emit ( 'error' , err ) ;
441
- }
442
- cb ( err ) ;
443
- return ;
444
- }
445
-
446
- completed ( ) ;
447
- }
448
- ) ( ) ;
426
+ runAsync ( function ( ) {
427
+ self . async = function ( ) {
428
+ return this . async ( ) ;
429
+ } . bind ( this ) ;
430
+
431
+ return method . apply ( self , self . args ) ;
432
+ } ) ( ) . then ( completed ) . catch ( function ( err ) {
433
+ debug ( 'An error occured while running ' + methodName , err ) ;
434
+
435
+ // Ensure we emit the error event outside the promise context so it won't be
436
+ // swallowed when there's no listeners.
437
+ setImmediate ( function ( ) {
438
+ self . emit ( 'error' , err ) ;
439
+ cb ( err ) ;
440
+ } ) ;
441
+ } ) ;
449
442
} ) ;
450
443
}
451
444
Original file line number Diff line number Diff line change @@ -319,23 +319,7 @@ describe('generators.Base', function () {
319
319
this . testGen . on ( 'error' , sinon . spy ( ) ) ;
320
320
this . testGen . run ( function ( err ) {
321
321
assert . equal ( err , error ) ;
322
- sinon . assert . notCalled ( spy ) ;
323
- done ( ) ;
324
- } ) ;
325
- } ) ;
326
-
327
- it ( 'stop queue processing once an error is thrown and "error" event has no listeners' , function ( done ) {
328
- var error = new Error ( ) ;
329
- var spy = sinon . spy ( ) ;
330
-
331
- this . TestGenerator . prototype . throwing = function ( ) {
332
- throw error ;
333
- } ;
334
- this . TestGenerator . prototype . afterError = spy ;
335
-
336
- this . testGen . run ( function ( err ) {
337
- assert . equal ( err , error ) ;
338
- sinon . assert . notCalled ( spy ) ;
322
+ sinon . assert . called ( spy ) ;
339
323
done ( ) ;
340
324
} ) ;
341
325
} ) ;
You can’t perform that action at this time.
0 commit comments