zorigami
Version:
a package for managing web workers
30 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var provide_worker_instance_1 = require("../../main_thread_api/provide_worker_instance");
var dispatch_message_from_worker_1 = require("../../main_thread_api/dispatch_message_from_worker");
function create_workers(worker_list) {
var all_workers = worker_list.map(function (_a) {
var WorkerConstructor = _a.WorkerConstructor, worker_name = _a.worker_name;
/* create the worker */
var new_worker_instance = new WorkerConstructor();
/* this should setup the worker to listen to the main worker
with it's default api, and setup it's custom API */
var new_worker_instance_name = worker_name;
/* start listening to messages from the worker */
new_worker_instance.onmessage = dispatch_message_from_worker_1.dispatch_message_from_worker;
/* store the worker instance in our class */
provide_worker_instance_1.default.storeWorker(new_worker_instance_name, new_worker_instance);
provide_worker_instance_1.default.storeWorkerInterface(new_worker_instance_name, new_worker_instance);
/* exhange main apis with the new worker. */
var new_worker_set = {
worker: new_worker_instance,
worker_name: new_worker_instance_name,
};
return new_worker_set;
});
console.log('all_workers', all_workers);
return all_workers;
}
exports.default = create_workers;
;
//# sourceMappingURL=create_workers.js.map