diff --git a/lib/index.js b/lib/index.js index d29c287..34abfdb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -319,6 +319,15 @@ function initSet(peer, config) { */ function load(id, cb) { assertDBPlugin(peer) + if (accountID === id) { + loaded(cb) + return + } + if (accountID !== null) { + // prettier-ignore + cb(new Error(`Cannot load Set for account "${id}" because Set for account "${accountID}" is already loaded`)) + return + } accountID = id loadPromise = new Promise((resolve, reject) => { for (const rec of peer.db.records()) { diff --git a/test/index.test.js b/test/index.test.js index 89911fd..03f538a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -31,6 +31,7 @@ test('setup', async (t) => { _nonce: 'alice', }) await p(peer.set.load)(aliceID) + await p(peer.set.load)(aliceID) // on purpose, test that re-load is idempotent peer.set.setGhostSpan(4) assert.equal(peer.set.getGhostSpan(), 4, 'getGhostSpan')