-
Notifications
You must be signed in to change notification settings - Fork 0
/
glua_worker.js
39 lines (35 loc) · 911 Bytes
/
glua_worker.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
30
31
32
33
34
35
36
37
38
39
/* globals gluaLintString, gluaPrettyPrintString */
self.importScripts("bower_components/glualint-lib/compiled.js")
let waitForFunction = function(funcName) {
return new Promise((resolve, reject) => {
if (typeof self[funcName] !== "undefined") {
resolve()
} else {
let interval = setInterval(() => {
if (typeof self[funcName] !== "undefined") {
clearInterval(interval)
resolve()
}
})
}
})
}
self.onmessage = (e) => {
if (e.data.action === "lint") {
waitForFunction("gluaLintString")
.then(() => {
postMessage({
id: e.data.id,
result: gluaLintString(e.data.code)
})
})
} else if (e.data.action === "prettyPrint") {
waitForFunction("gluaPrettyPrintString")
.then(() => {
postMessage({
id: e.data.id,
result: gluaPrettyPrintString(e.data.code)
})
})
}
}