pep8analysis: do work async using workers
[nit.git] / contrib / pep8analysis / www / worker.js
diff --git a/contrib/pep8analysis/www/worker.js b/contrib/pep8analysis/www/worker.js
new file mode 100644 (file)
index 0000000..6b20007
--- /dev/null
@@ -0,0 +1,27 @@
+// load
+var Module = {
+       'print': function(text) {
+               postMessage({'type': 'stdout', 'data': text})
+       },
+       'TOTAL_MEMORY': 512000000
+}
+importScripts("pep8analysis.js")
+run_analysis = Module.cwrap('pep8analysis_web___NativeString_run_analysis', null, ['string'])
+
+function show_graph(data) {
+       postMessage({'type':"show_graph", 'data': data})
+}
+
+// notify UI it's ready
+postMessage({'type':"ready"})
+
+// wait for code to analyze
+self.onmessage = function(event){
+       try {
+               run_analysis(event.data)
+               postMessage({'type':"complete"})
+       } catch(e) {
+               console.log(e)
+               postMessage({'type':"exception", 'data': e.toString()})
+       }
+}