Skip to content

Commit 65f60d3

Browse files
committed
fix: close root datastore after initialized check
1 parent 0c016c5 commit 65f60d3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,21 @@ class IpfsRepo {
7474
* @returns {Promise<Boolean>}
7575
*/
7676
async isInitialized () {
77+
if (!this.closed) {
78+
// repo is open, must be initialized
79+
return true
80+
}
81+
7782
try {
83+
// have to open the root datastore in the browser before
84+
// we can check whether it's been initialized
7885
await this._openRoot()
7986
await this._checkInitialized()
80-
// necessary? await this.root.close()
87+
await this.root.close()
8188

8289
return true
8390
} catch (err) {
91+
// FIXME: do not use exceptions for flow control
8492
return false
8593
}
8694
}

test/is-initialized.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ describe('isInitialized', () => {
2525
await repo.init({})
2626
expect(await repo.isInitialized()).to.be.true()
2727
})
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+
})
2841
})

0 commit comments

Comments
 (0)