@@ -8,14 +8,14 @@ class ShardManager extends Collection {
88 constructor ( client ) {
99 super ( Shard ) ;
1010 this . _client = client ;
11-
11+ this . maxConcurrency = 1 ;
1212 this . connectQueue = [ ] ;
1313 this . lastConnect = 0 ;
1414 this . connectTimeout = null ;
1515 }
1616
1717 connect ( shard ) {
18- if ( shard . sessionID || ( this . lastConnect <= Date . now ( ) - 5000 && ! this . find ( ( shard ) => shard . connecting ) ) ) {
18+ if ( ( shard . sessionID || ( this . lastConnect <= Date . now ( ) - 5000 && ! this . find ( ( shard ) => shard . connecting ) ) ) && ! this . _client . options . useMaxConcurrency ) {
1919 shard . connect ( ) ;
2020 this . lastConnect = Date . now ( ) + 7500 ;
2121 } else {
@@ -95,17 +95,31 @@ class ShardManager extends Collection {
9595 }
9696 }
9797
98+ // https://github.com/curtisf/eris/commit/6b8397da17c2fabf37f5c08f40899c5131d599fb#diff-df83f51ebdee7648e64537556e67de936a1f8a78c2e4459b49a5b850a35cdfa2
9899 tryConnect ( ) {
99100 if ( this . connectQueue . length > 0 ) {
100- if ( this . lastConnect <= Date . now ( ) - 5000 ) {
101- const shard = this . connectQueue . shift ( ) ;
102- shard . connect ( ) ;
103- this . lastConnect = Date . now ( ) + 7500 ;
104- } else if ( ! this . connectTimeout ) {
105- this . connectTimeout = setTimeout ( ( ) => {
106- this . connectTimeout = null ;
107- this . tryConnect ( ) ;
108- } , 1000 ) ;
101+ if ( ! this . _client . options . useMaxConcurrency ) {
102+ if ( this . lastConnect <= Date . now ( ) - 5000 ) {
103+ const shard = this . connectQueue . shift ( ) ;
104+ shard . connect ( ) ;
105+ this . lastConnect = Date . now ( ) + 7500 ;
106+ } else if ( ! this . connectTimeout ) {
107+ this . connectTimeout = setTimeout ( ( ) => {
108+ this . connectTimeout = null ;
109+ this . tryConnect ( ) ;
110+ } , 1000 ) ;
111+ }
112+ } else {
113+ if ( this . filter ( ( shard ) => shard . connecting ) . length < this . maxConcurrency ) {
114+ const shard = this . connectQueue . shift ( ) ;
115+ shard . connect ( ) ;
116+ //this.lastConnect = Date.now() + 7500;
117+ } else if ( ! this . connectTimeout ) {
118+ this . connectTimeout = setTimeout ( ( ) => {
119+ this . connectTimeout = null ;
120+ this . tryConnect ( ) ;
121+ } , 250 ) ;
122+ }
109123 }
110124 }
111125 }
0 commit comments