@@ -57,28 +57,11 @@ export class FuelDB extends Dexie {
57
57
} ) ;
58
58
this . on ( 'blocked' , ( ) => this . restart ( 'blocked' ) ) ;
59
59
this . on ( 'close' , ( ) => this . restart ( 'close' ) ) ;
60
- this . on ( 'message' , ( e ) => {
61
- console . log ( 'fsk changed' , e ) ;
62
- } ) ;
63
60
}
64
61
65
- open ( ) {
66
- return this . safeOpen ( ) . finally ( ( ) =>
67
- this . watchConnection ( )
68
- ) as PromiseExtended < Dexie > ;
69
- }
70
-
71
- close ( safeClose = false ) {
72
- if ( safeClose ) {
73
- this . restartAttempts = 0 ;
74
- clearInterval ( this . integrityCheckInterval ) ;
75
- }
76
- return super . close ( ) ;
77
- }
78
-
79
- async safeOpen ( ) {
62
+ open ( ) : PromiseExtended < Dexie > {
80
63
try {
81
- const result = await super . open ( ) ;
64
+ const result = super . open ( ) ;
82
65
this . restartAttempts = 0 ;
83
66
return result ;
84
67
} catch ( err ) {
@@ -88,27 +71,13 @@ export class FuelDB extends Dexie {
88
71
}
89
72
}
90
73
91
- async ensureDatabaseOpen ( ) {
92
- if ( this . isOpen ( ) && ! this . hasBeenClosed ( ) && ! this . hasFailed ( ) ) return ;
93
-
94
- if ( this . restartAttempts > 3 ) {
95
- console . error ( 'Reached max attempts to open DB. Sending restart signal.' ) ;
96
- this . restart ( 'blocked' ) ;
97
- return ;
74
+ async close ( safeClose = false ) {
75
+ if ( ! this . alwaysOpen || safeClose || this . restartAttempts > 3 ) {
76
+ this . restartAttempts = 0 ;
77
+ return super . close ( ) ;
98
78
}
99
-
100
79
this . restartAttempts += 1 ;
101
- console . warn ( 'DB is not open. Attempting restart.' ) ;
102
- await this . safeOpen ( ) ;
103
- }
104
-
105
- watchConnection ( ) {
106
- if ( ! this . alwaysOpen ) return ;
107
-
108
- clearInterval ( this . integrityCheckInterval ) ;
109
- this . integrityCheckInterval = setInterval ( ( ) => {
110
- this . ensureDatabaseOpen ( ) ;
111
- } , 1000 ) ;
80
+ await this . open ( ) . catch ( ( ) => this . close ( ) ) ;
112
81
}
113
82
114
83
async restart ( eventName : FailureEvents ) {
0 commit comments