@@ -43,11 +43,7 @@ Bottleneck = function () {
4343 class Bottleneck {
4444 constructor ( options = { } , ...invalid ) {
4545 var storeInstanceOptions , storeOptions ;
46- this . _drainOne = this . _drainOne . bind ( this ) ;
47- this . submit = this . submit . bind ( this ) ;
48- this . schedule = this . schedule . bind ( this ) ;
49- this . updateSettings = this . updateSettings . bind ( this ) ;
50- this . incrementReservoir = this . incrementReservoir . bind ( this ) ;
46+ this . _addToQueue = this . _addToQueue . bind ( this ) ;
5147
5248 this . _validateOptions ( options , invalid ) ;
5349
@@ -351,7 +347,7 @@ Bottleneck = function () {
351347 return waitForExecuting ( 1 ) ;
352348 } ) ;
353349
354- this . _addToQueue = function ( job ) {
350+ this . _receive = function ( job ) {
355351 return job . _reject ( new Bottleneck . prototype . BottleneckError ( options . enqueueErrorMessage ) ) ;
356352 } ;
357353
@@ -365,25 +361,17 @@ Bottleneck = function () {
365361 _addToQueue ( job ) {
366362 var _this2 = this ;
367363
368- var args , options ;
369- args = job . args ;
370- options = job . options ;
371-
372- if ( ! job . doReceive ( ) ) {
373- return false ;
374- }
375-
376- return this . _submitLock . schedule (
377- /*#__PURE__*/
378- _asyncToGenerator ( function * ( ) {
379- var blocked , error , reachedHWM , shifted , strategy ;
364+ return _asyncToGenerator ( function * ( ) {
365+ var args , blocked , error , options , reachedHWM , shifted , strategy ;
366+ args = job . args ;
367+ options = job . options ;
380368
381369 try {
382- var _ref3 = yield _this2 . _store . __submit__ ( _this2 . queued ( ) , options . weight ) ;
370+ var _ref2 = yield _this2 . _store . __submit__ ( _this2 . queued ( ) , options . weight ) ;
383371
384- reachedHWM = _ref3 . reachedHWM ;
385- blocked = _ref3 . blocked ;
386- strategy = _ref3 . strategy ;
372+ reachedHWM = _ref2 . reachedHWM ;
373+ blocked = _ref2 . blocked ;
374+ strategy = _ref2 . strategy ;
387375 } catch ( error1 ) {
388376 error = error1 ;
389377
@@ -424,21 +412,29 @@ Bottleneck = function () {
424412
425413 yield _this2 . _drainAll ( ) ;
426414 return reachedHWM ;
427- } ) ) ;
415+ } ) ( ) ;
416+ }
417+
418+ _receive ( job ) {
419+ if ( job . doReceive ( ) ) {
420+ return this . _submitLock . schedule ( this . _addToQueue , job ) ;
421+ } else {
422+ return false ;
423+ }
428424 }
429425
430426 submit ( ...args ) {
431427 var cb , fn , job , options , ref , ref1 , task ;
432428
433429 if ( typeof args [ 0 ] === "function" ) {
434- var _ref4 , _ref5 , _splice$call , _splice$call2 ;
430+ var _ref3 , _ref4 , _splice$call , _splice$call2 ;
435431
436- ref = args , ( _ref4 = ref , _ref5 = _toArray ( _ref4 ) , fn = _ref5 [ 0 ] , args = _ref5 . slice ( 1 ) , _ref4 ) , ( _splice$call = splice . call ( args , - 1 ) , _splice$call2 = _slicedToArray ( _splice$call , 1 ) , cb = _splice$call2 [ 0 ] , _splice$call ) ;
432+ ref = args , ( _ref3 = ref , _ref4 = _toArray ( _ref3 ) , fn = _ref4 [ 0 ] , args = _ref4 . slice ( 1 ) , _ref3 ) , ( _splice$call = splice . call ( args , - 1 ) , _splice$call2 = _slicedToArray ( _splice$call , 1 ) , cb = _splice$call2 [ 0 ] , _splice$call ) ;
437433 options = parser . load ( { } , this . jobDefaults ) ;
438434 } else {
439- var _ref6 , _ref7 , _splice$call3 , _splice$call4 ;
435+ var _ref5 , _ref6 , _splice$call3 , _splice$call4 ;
440436
441- ref1 = args , ( _ref6 = ref1 , _ref7 = _toArray ( _ref6 ) , options = _ref7 [ 0 ] , fn = _ref7 [ 1 ] , args = _ref7 . slice ( 2 ) , _ref6 ) , ( _splice$call3 = splice . call ( args , - 1 ) , _splice$call4 = _slicedToArray ( _splice$call3 , 1 ) , cb = _splice$call4 [ 0 ] , _splice$call3 ) ;
437+ ref1 = args , ( _ref5 = ref1 , _ref6 = _toArray ( _ref5 ) , options = _ref6 [ 0 ] , fn = _ref6 [ 1 ] , args = _ref6 . slice ( 2 ) , _ref5 ) , ( _splice$call3 = splice . call ( args , - 1 ) , _splice$call4 = _slicedToArray ( _splice$call3 , 1 ) , cb = _splice$call4 [ 0 ] , _splice$call3 ) ;
442438 options = parser . load ( options , this . jobDefaults ) ;
443439 }
444440
@@ -460,7 +456,7 @@ Bottleneck = function () {
460456 return typeof cb === "function" ? cb ( args ) : void 0 ;
461457 }
462458 } ) ;
463- return this . _addToQueue ( job ) ;
459+ return this . _receive ( job ) ;
464460 }
465461
466462 schedule ( ...args ) {
@@ -486,20 +482,20 @@ Bottleneck = function () {
486482
487483 job = new Job ( task , args , options , this . jobDefaults , this . rejectOnDrop , this . Events , this . _states , this . Promise ) ;
488484
489- this . _addToQueue ( job ) ;
485+ this . _receive ( job ) ;
490486
491487 return job . promise ;
492488 }
493489
494490 wrap ( fn ) {
495491 var schedule , wrapped ;
496- schedule = this . schedule ;
492+ schedule = this . schedule . bind ( this ) ;
497493
498494 wrapped = function wrapped ( ...args ) {
499495 return schedule ( fn . bind ( this ) , ...args ) ;
500496 } ;
501497
502- wrapped . withOptions = ( options , ...args ) => {
498+ wrapped . withOptions = function ( options , ...args ) {
503499 return schedule ( options , fn , ...args ) ;
504500 } ;
505501
0 commit comments