MCPcopy Create free account
hub / github.com/TruthHun/BookStack / WorkerServer

Function WorkerServer

static/editor.md/lib/codemirror/addon/tern/tern.js:660–696  ·  view source on GitHub ↗
(ts)

Source from the content-addressed store, hash-verified

658 // Worker wrapper
659
660 function WorkerServer(ts) {
661 var worker = ts.worker = new Worker(ts.options.workerScript);
662 worker.postMessage({type: "init",
663 defs: ts.options.defs,
664 plugins: ts.options.plugins,
665 scripts: ts.options.workerDeps});
666 var msgId = 0, pending = {};
667
668 function send(data, c) {
669 if (c) {
670 data.id = ++msgId;
671 pending[msgId] = c;
672 }
673 worker.postMessage(data);
674 }
675 worker.onmessage = function(e) {
676 var data = e.data;
677 if (data.type == "getFile") {
678 getFile(ts, data.name, function(err, text) {
679 send({type: "getFile", err: String(err), text: text, id: data.id});
680 });
681 } else if (data.type == "debug") {
682 window.console.log(data.message);
683 } else if (data.id && pending[data.id]) {
684 pending[data.id](data.err, data.body);
685 delete pending[data.id];
686 }
687 };
688 worker.onerror = function(e) {
689 for (var id in pending) pending[id](e);
690 pending = {};
691 };
692
693 this.addFile = function(name, text) { send({type: "add", name: name, text: text}); };
694 this.delFile = function(name) { send({type: "del", name: name}); };
695 this.request = function(body, c) { send({type: "req", body: body}, c); };
696 }
697});

Callers

nothing calls this directly

Calls 2

getFileFunction · 0.70
sendFunction · 0.70

Tested by

no test coverage detected