19 lines
621 B
TypeScript
19 lines
621 B
TypeScript
export class SnapshotOrder {
|
|
private runtimeId = '';
|
|
private revision = -1;
|
|
private retired = new Set<string>();
|
|
|
|
accept(value: { runtimeId?: string; revision?: number }): boolean {
|
|
if (!value.runtimeId || !Number.isSafeInteger(value.revision)) return true;
|
|
if (this.retired.has(value.runtimeId)) return false;
|
|
if (value.runtimeId !== this.runtimeId) {
|
|
if (this.runtimeId) this.retired.add(this.runtimeId);
|
|
this.runtimeId = value.runtimeId;
|
|
this.revision = -1;
|
|
}
|
|
if (value.revision! <= this.revision) return false;
|
|
this.revision = value.revision!;
|
|
return true;
|
|
}
|
|
}
|