File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -74,13 +74,21 @@ class IpfsRepo {
74
74
* @returns {Promise<Boolean> }
75
75
*/
76
76
async isInitialized ( ) {
77
+ if ( ! this . closed ) {
78
+ // repo is open, must be initialized
79
+ return true
80
+ }
81
+
77
82
try {
83
+ // have to open the root datastore in the browser before
84
+ // we can check whether it's been initialized
78
85
await this . _openRoot ( )
79
86
await this . _checkInitialized ( )
80
- // necessary? await this.root.close()
87
+ await this . root . close ( )
81
88
82
89
return true
83
90
} catch ( err ) {
91
+ // FIXME: do not use exceptions for flow control
84
92
return false
85
93
}
86
94
}
Original file line number Diff line number Diff line change @@ -25,4 +25,17 @@ describe('isInitialized', () => {
25
25
await repo . init ( { } )
26
26
expect ( await repo . isInitialized ( ) ) . to . be . true ( )
27
27
} )
28
+
29
+ it ( 'should be true after initialization and opening' , async ( ) => {
30
+ await repo . init ( { } )
31
+ await repo . open ( )
32
+ expect ( await repo . isInitialized ( ) ) . to . be . true ( )
33
+ } )
34
+
35
+ it ( 'should be true after initialization, opening and closing' , async ( ) => {
36
+ await repo . init ( { } )
37
+ await repo . open ( )
38
+ await repo . close ( )
39
+ expect ( await repo . isInitialized ( ) ) . to . be . true ( )
40
+ } )
28
41
} )
You can’t perform that action at this time.
0 commit comments