-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
29 lines (23 loc) · 842 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
ffxiv_static_solver = {};
ffxiv_static_solver.initialize = async () => {
const solver = new Worker("./ffxiv-static-solver/worker.js");
solver.postMessage("init")
const workerReady = new Promise((resolve, _reject) => {
// the first message we recieve back is letting us know that initialization is complete
solver.onmessage = (_event) => {
const solve = (definitions, desired_composition, job_preferences) => {
var receive = null
const solutionReady = new Promise((inner_resolve, _inner_reject) => {
receive = (event) => {
inner_resolve(event.data)
}
})
solver.onmessage = receive
solver.postMessage([definitions, desired_composition, job_preferences])
return solutionReady
}
resolve(solve)
}
})
return workerReady
}