Skip to content

Commit

Permalink
fix: close root datastore after initialized check
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Feb 10, 2020
1 parent 0c016c5 commit 65f60d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ class IpfsRepo {
* @returns {Promise<Boolean>}
*/
async isInitialized () {
if (!this.closed) {
// repo is open, must be initialized
return true
}

try {
// have to open the root datastore in the browser before
// we can check whether it's been initialized
await this._openRoot()
await this._checkInitialized()
// necessary? await this.root.close()
await this.root.close()

return true
} catch (err) {
// FIXME: do not use exceptions for flow control
return false
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/is-initialized.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ describe('isInitialized', () => {
await repo.init({})
expect(await repo.isInitialized()).to.be.true()
})

it('should be true after initialization and opening', async () => {
await repo.init({})
await repo.open()
expect(await repo.isInitialized()).to.be.true()
})

it('should be true after initialization, opening and closing', async () => {
await repo.init({})
await repo.open()
await repo.close()
expect(await repo.isInitialized()).to.be.true()
})
})

0 comments on commit 65f60d3

Please sign in to comment.