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

app: model: Simplify Hub model

parent 7835bd0d
No related merge requests found
...@@ -39,39 +39,23 @@ class Hub { ...@@ -39,39 +39,23 @@ class Hub {
let indexLambda = index.bind(this) let indexLambda = index.bind(this)
let unindexLambda = unindex.bind(this) let unindexLambda = unindex.bind(this)
this.wait = (id, locations) => { this.waitAsync = async (id, locations) => {
let rejectCallback = null let promise = new Promise((resolve, reject) => {
this.drivers[id] = {
let promise = (async () => { resolve: resolve,
let promise = new Promise((resolve, reject) => { reject: reject
this.drivers[id] = {
resolve: resolve,
reject: reject
}
// Keep reject callback.
rejectCallback = reject
// Index locations.
indexLambda(id, locations)
})
try {
let userId = await promise
return userId
} finally {
// Remove indexed locations.
unindexLambda(id, locations)
} }
})()
return { // Index locations.
promise: promise, indexLambda(id, locations)
})
reject (err) { let userId = await promise
rejectCallback(err)
} // Remove indexed locations.
} unindexLambda(id, locations)
return userId
} }
} }
...@@ -82,6 +66,10 @@ class Hub { ...@@ -82,6 +66,10 @@ class Hub {
pick (id, userId) { pick (id, userId) {
this.drivers[id].resolve(userId) this.drivers[id].resolve(userId)
} }
reject (id, reason) {
this.drivers[id].reject(reason)
}
} }
module.exports = Hub module.exports = Hub
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