MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / WorkerServer

Function WorkerServer

lib/web/CodeMirror/addon/tern/tern.js:682–718  ·  view source on GitHub ↗
(ts)

Source from the content-addressed store, hash-verified

680 // Worker wrapper
681
682 function WorkerServer(ts) {
683 var worker = ts.worker = new Worker(ts.options.workerScript);
684 worker.postMessage({type: "init",
685 defs: ts.options.defs,
686 plugins: ts.options.plugins,
687 scripts: ts.options.workerDeps});
688 var msgId = 0, pending = {};
689
690 function send(data, c) {
691 if (c) {
692 data.id = ++msgId;
693 pending[msgId] = c;
694 }
695 worker.postMessage(data);
696 }
697 worker.onmessage = function(e) {
698 var data = e.data;
699 if (data.type == "getFile") {
700 getFile(ts, data.name, function(err, text) {
701 send({type: "getFile", err: String(err), text: text, id: data.id});
702 });
703 } else if (data.type == "debug") {
704 window.console.log(data.message);
705 } else if (data.id && pending[data.id]) {
706 pending[data.id](data.err, data.body);
707 delete pending[data.id];
708 }
709 };
710 worker.onerror = function(e) {
711 for (var id in pending) pending[id](e);
712 pending = {};
713 };
714
715 this.addFile = function(name, text) { send({type: "add", name: name, text: text}); };
716 this.delFile = function(name) { send({type: "del", name: name}); };
717 this.request = function(body, c) { send({type: "req", body: body}, c); };
718 }
719});

Callers

nothing calls this directly

Calls 3

logMethod · 0.80
getFileFunction · 0.70
sendFunction · 0.70

Tested by

no test coverage detected