System.register([], function (_export, _context) {
  "use strict";

  var workers;
  return {
    setters: [],
    execute: function () {
      _recorder_._src_worker_systemjs_worker_js = _recorder_._src_worker_systemjs_worker_js || {};

      _export("workers", workers = _recorder_._src_worker_systemjs_worker_js.workers);

      _export("workers", workers);

      _recorder_._src_worker_systemjs_worker_js.workers = workers;
      class SystemjsWorker {

        static get workers() {
          if (!_recorder_._src_worker_systemjs_worker_js.workers) _recorder_._src_worker_systemjs_worker_js.workers = new Set();
          return _recorder_._src_worker_systemjs_worker_js.workers;
        }

        constructor(url) {
          this.metaworker = new Worker("src/worker/meta-worker.js");
          // bootstrap onmessage
          this.loaded = new Promise(resolve => {
            this.metaworker.onmessage = evt => {
              var msg = evt.data;
              console.log("bootstrap onmessage", msg);
              if (msg.message == "error") {
                lively.error("[systemjs-worker]", msg.error || msg.value);
              }
              if (msg.message == "loaded") {
                console.log("worker loaded", url);
                this.metaworker.onmessage = msg => {
                  console.log("new onmessage");
                  this.onmessage(msg);
                };
                resolve // worker should accept postMessages now...
                ();
              }
            };
          });
          this.metaworker.postMessage({ message: "load", url: url });
          _recorder_._src_worker_systemjs_worker_js.SystemjsWorker.workers.add(this);
        }

        onmessage(evt) {
          // do nothing
        }

        terminate() {
          this.metaworker.terminate();
          _recorder_._src_worker_systemjs_worker_js.SystemjsWorker.workers.delete(this);
        }

        async postMessage(msg) {
          await this.loaded;
          this.metaworker.postMessage(msg);
        }

      }

      _export("default", SystemjsWorker);

      _recorder_._src_worker_systemjs_worker_js.SystemjsWorker = SystemjsWorker;
    }
  };
});