Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
charlielye committed Apr 9, 2024
1 parent f220e91 commit 957bda7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
7 changes: 2 additions & 5 deletions yarn-project/kv-store/src/mem/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ export class MemAztecCounter implements AztecCounter<Key> {
this.map = new MemAztecMap(name, db, false);
}

async set(key: Key, value: number): Promise<boolean> {
async set(key: Key, value: number): Promise<void> {
if (value) {
return this.map.set(key, value);
} else {
await this.map.delete(key);
return true;
}
}

async update(key: Key, delta = 1): Promise<boolean> {
async update(key: Key, delta = 1): Promise<void> {
const current = this.map.get(key) ?? 0;
const next = current + delta;

Expand All @@ -32,8 +31,6 @@ export class MemAztecCounter implements AztecCounter<Key> {
if (next > 0) {
await this.map.set(key, next);
}

return true;
}

get(key: Key): number {
Expand Down
13 changes: 6 additions & 7 deletions yarn-project/kv-store/src/mem/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ export class MemAztecMap<V> implements AztecMultiMap<Key, V> {
return r ? r.length > 0 : false;
}

set(key: Key, val: V): Promise<boolean> {
set(key: Key, val: V): Promise<void> {
const r = this.db.get(this.slot(key));
if (r && this.allowDups) {
this.db.set(this.slot(key), [...r, val]);
} else {
this.db.set(this.slot(key), [val]);
}
return Promise.resolve(true);
return Promise.resolve();
}

swap(key: Key, fn: (val: V | undefined) => V): Promise<boolean> {
swap(key: Key, fn: (val: V | undefined) => V): Promise<void> {
const entry = this.get(key);
const newValue = fn(entry);
this.db.set(this.slot(key), [newValue]);
return Promise.resolve(true);
return Promise.resolve();
}

async setIfNotExists(key: Key, val: V): Promise<boolean> {
Expand All @@ -78,13 +78,12 @@ export class MemAztecMap<V> implements AztecMultiMap<Key, V> {
return false;
}

delete(key: Key): Promise<boolean> {
delete(key: Key): Promise<void> {
const r = this.db.get(this.slot(key));
if (r?.length) {
this.db.set(this.slot(key), []);
return Promise.resolve(true);
}
return Promise.resolve(false);
return Promise.resolve();
}

deleteValue(key: Key, val: V): Promise<void> {
Expand Down

0 comments on commit 957bda7

Please sign in to comment.