[verified] refactor: harden operations and redesign device console
This commit is contained in:
@@ -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) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user