File tree 3 files changed +16
-5
lines changed
3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,8 @@ var Remote = (function() {
19
19
this . transport = new Transport ( {
20
20
cache : o . cache ,
21
21
limiter : o . limiter ,
22
- transport : o . transport
22
+ transport : o . transport ,
23
+ maxPendingRequests : o . maxPendingRequests
23
24
} ) ;
24
25
}
25
26
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ var Transport = (function() {
9
9
10
10
var pendingRequestsCount = 0 ,
11
11
pendingRequests = { } ,
12
- maxPendingRequests = 6 ,
13
12
sharedCache = new LruCache ( 10 ) ;
14
13
15
14
// constructor
@@ -18,6 +17,7 @@ var Transport = (function() {
18
17
function Transport ( o ) {
19
18
o = o || { } ;
20
19
20
+ this . maxPendingRequests = o . maxPendingRequests || 6 ;
21
21
this . cancelled = false ;
22
22
this . lastReq = null ;
23
23
@@ -31,7 +31,7 @@ var Transport = (function() {
31
31
// --------------
32
32
33
33
Transport . setMaxPendingRequests = function setMaxPendingRequests ( num ) {
34
- maxPendingRequests = num ;
34
+ this . maxPendingRequests = num ;
35
35
} ;
36
36
37
37
Transport . resetCache = function resetCache ( ) {
@@ -65,7 +65,7 @@ var Transport = (function() {
65
65
}
66
66
67
67
// under the pending request threshold, so fire off a request
68
- else if ( pendingRequestsCount < maxPendingRequests ) {
68
+ else if ( pendingRequestsCount < this . maxPendingRequests ) {
69
69
pendingRequestsCount ++ ;
70
70
pendingRequests [ fingerprint ] =
71
71
this . _send ( o ) . done ( done ) . fail ( fail ) . always ( always ) ;
Original file line number Diff line number Diff line change @@ -32,7 +32,17 @@ describe('Transport', function() {
32
32
expect ( spy ) . toHaveBeenCalledWith ( null , resp . parsed ) ;
33
33
} ) ;
34
34
35
- it ( 'should respect maxPendingRequests configuration' , function ( ) {
35
+ it ( 'should use maxPendingRequests configuration option' , function ( ) {
36
+ this . transport = new Transport ( { transport : $ . ajax , maxPendingRequests : 2 } ) ;
37
+
38
+ for ( var i = 0 ; i < 5 ; i ++ ) {
39
+ this . transport . get ( '/test' + i , $ . noop ) ;
40
+ }
41
+
42
+ expect ( ajaxRequests . length ) . toBe ( 2 ) ;
43
+ } ) ;
44
+
45
+ it ( 'should open up to 6 maxPendingRequests by default' , function ( ) {
36
46
for ( var i = 0 ; i < 10 ; i ++ ) {
37
47
this . transport . get ( '/test' + i , $ . noop ) ;
38
48
}
You can’t perform that action at this time.
0 commit comments