mirror of https://codeberg.org/pzp/pzp-set.git
load() should be idempotent
This commit is contained in:
parent
cb1027b8b2
commit
650c0110dd
|
@ -319,6 +319,15 @@ function initSet(peer, config) {
|
||||||
*/
|
*/
|
||||||
function load(id, cb) {
|
function load(id, cb) {
|
||||||
assertDBPlugin(peer)
|
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
|
accountID = id
|
||||||
loadPromise = new Promise((resolve, reject) => {
|
loadPromise = new Promise((resolve, reject) => {
|
||||||
for (const rec of peer.db.records()) {
|
for (const rec of peer.db.records()) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ test('setup', async (t) => {
|
||||||
_nonce: 'alice',
|
_nonce: 'alice',
|
||||||
})
|
})
|
||||||
await p(peer.set.load)(aliceID)
|
await p(peer.set.load)(aliceID)
|
||||||
|
await p(peer.set.load)(aliceID) // on purpose, test that re-load is idempotent
|
||||||
|
|
||||||
peer.set.setGhostSpan(4)
|
peer.set.setGhostSpan(4)
|
||||||
assert.equal(peer.set.getGhostSpan(), 4, 'getGhostSpan')
|
assert.equal(peer.set.getGhostSpan(), 4, 'getGhostSpan')
|
||||||
|
|
Loading…
Reference in New Issue