[verified] refactor: harden operations and redesign device console

This commit is contained in:
chick
2026-07-15 16:33:16 +08:00
parent e04a16e817
commit 4977afdc20
24 changed files with 769 additions and 779 deletions
+9 -4
View File
@@ -1,14 +1,19 @@
export class RequestCoordinator {
#versions = new Map()
async run(channel, ownerId, operation) {
next(channel) {
const version = (this.#versions.get(channel) || 0) + 1
this.#versions.set(channel, version)
return version
}
isCurrent(channel, version) { return this.#versions.get(channel) === version }
async run(channel, ownerId, operation) {
const version = this.next(channel)
try {
const value = await operation()
return { accepted: this.#versions.get(channel) === version, ownerId, value }
return { accepted: this.isCurrent(channel, version), ownerId, value }
} catch (error) {
return { accepted: this.#versions.get(channel) === version, ownerId, error }
return { accepted: this.isCurrent(channel, version), ownerId, error }
}
}
invalidate(channel) { this.#versions.set(channel, (this.#versions.get(channel) || 0) + 1) }
invalidate(channel) { return this.next(channel) }
}