Skip to content
Snippets Groups Projects
Commit d7e158d6 authored by Daniel's avatar Daniel
Browse files

app/model: Hub: Add ability for multi. instances

parent 8e0a97ec
Branches
No related merge requests found
......@@ -41,10 +41,19 @@ class Hub {
this.waitAsync = async (id, locations, rejectFunc) => {
let promise = new Promise((resolve, reject) => {
this.drivers[id] = {
let devices = this.drivers[id]
// Keep device informations.
if (!devices) {
devices = []
this.drivers[id] = devices
}
devices.push({
resolve: resolve,
reject: reject
}
})
// Pass reject function.
if (rejectFunc) {
......@@ -55,25 +64,41 @@ class Hub {
indexLambda(id, locations)
})
let userId = await promise
// Remove indexed locations.
unindexLambda(id, locations)
try {
return await promise
} finally {
// Remove indexed locations.
unindexLambda(id, locations)
return userId
delete this.drivers[id]
}
}
}
filter (location) {
return this.locations[location]
return [...this.locations[location] || []]
}
pick (id, userId) {
this.drivers[id].resolve(userId)
let handle = this.drivers[id]
if (handle) {
handle.forEach(h => h.resolve(userId))
return true
}
return false
}
reject (id, reason) {
this.drivers[id].reject(reason)
let handle = this.drivers[id]
if (handle) {
handle.forEach(h => h.reject(reason))
return true
}
return false
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment