File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
packages/libsql-client/src Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -403,6 +403,35 @@ export class WsClient implements Client {
403403 }
404404 }
405405
406+ async reconnect ( ) : Promise < void > {
407+ try {
408+ for ( const st of Array . from ( this . #connState. streamStates ) ) {
409+ try {
410+ st . stream . close ( ) ;
411+ } catch { }
412+ }
413+ this . #connState. client . close ( ) ;
414+ } catch { }
415+
416+ if ( this . #futureConnState) {
417+ try {
418+ this . #futureConnState. client . close ( ) ;
419+ } catch { }
420+ this . #futureConnState = undefined ;
421+ }
422+
423+ const next = this . #openConn( ) ;
424+ const version = await next . client . getVersion ( ) ;
425+
426+ next . useSqlCache = version >= 2 ;
427+ if ( next . useSqlCache ) {
428+ next . sqlCache . capacity = sqlCacheCapacity ;
429+ }
430+
431+ this . #connState = next ;
432+ this . closed = false ;
433+ }
434+
406435 _closeStream ( streamState : StreamState ) : void {
407436 streamState . stream . close ( ) ;
408437
@@ -421,6 +450,13 @@ export class WsClient implements Client {
421450 close ( ) : void {
422451 this . #connState. client . close ( ) ;
423452 this . closed = true ;
453+ if ( this . #futureConnState) {
454+ try {
455+ this . #futureConnState. client . close ( ) ;
456+ } catch { }
457+ this . #futureConnState = undefined ;
458+ }
459+ this . closed = true ;
424460 }
425461}
426462
You can’t perform that action at this time.
0 commit comments