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

app: model: Simplify Hub model

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