feat: promise for commit and rollback
This commit is contained in:
4
src/cache/SortKeyCache.ts
vendored
4
src/cache/SortKeyCache.ts
vendored
@@ -53,9 +53,9 @@ export interface SortKeyCache<V> {
|
||||
|
||||
begin(): Promise<void>;
|
||||
|
||||
rollback(): void;
|
||||
rollback(): Promise<void>;
|
||||
|
||||
commit(): void;
|
||||
commit(): Promise<void>;
|
||||
|
||||
/**
|
||||
* used mostly for debugging, allows to dump the current content cache
|
||||
|
||||
@@ -87,8 +87,6 @@ export interface StateEvaluator {
|
||||
|
||||
lastCachedSortKey(): Promise<string | null>;
|
||||
|
||||
allCachedContracts(): Promise<string[]>;
|
||||
|
||||
setCache(cache: SortKeyCache<EvalStateResult<unknown>>): void;
|
||||
|
||||
getCache(): SortKeyCache<EvalStateResult<unknown>>;
|
||||
|
||||
@@ -224,10 +224,6 @@ export class CacheableStateEvaluator extends DefaultStateEvaluator {
|
||||
return await this.cache.getLastSortKey();
|
||||
}
|
||||
|
||||
async allCachedContracts(): Promise<string[]> {
|
||||
return await this.cache.keys();
|
||||
}
|
||||
|
||||
setCache(cache: SortKeyCache<EvalStateResult<unknown>>): void {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@@ -417,8 +417,6 @@ export abstract class DefaultStateEvaluator implements StateEvaluator {
|
||||
|
||||
abstract lastCachedSortKey(): Promise<string | null>;
|
||||
|
||||
abstract allCachedContracts(): Promise<string[]>;
|
||||
|
||||
abstract setCache(cache: SortKeyCache<EvalStateResult<unknown>>): void;
|
||||
|
||||
abstract getCache(): SortKeyCache<EvalStateResult<unknown>>;
|
||||
|
||||
@@ -322,16 +322,16 @@ export class KV {
|
||||
async commit(): Promise<void> {
|
||||
if (this._storage) {
|
||||
if (this._transaction.dryRun) {
|
||||
this._storage.rollback();
|
||||
await this._storage.rollback();
|
||||
} else {
|
||||
this._storage.commit();
|
||||
await this._storage.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async rollback(): Promise<void> {
|
||||
if (this._storage) {
|
||||
this._storage.rollback();
|
||||
await this._storage.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user