developit / web-worker

Consistent Web Workers in browser and Node.

Home Page:https://npm.im/web-worker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for importScripts()

developit opened this issue · comments

The implementation could be relatively simple:

const vm = require('vm');
const fs = require('fs');
function importScripts() {
  for (var i=0; i<arguments.length; i++) {
    var url = arguments[i];
    vm.runInThisContext(fs.readFileSync(url,'utf-8')),{ filename: url });
  }
}

Hi! I would like to help, but is that all the context or really is so easy as the example?

@metcoder95 it should really just be that easy! We will just want to make sure this is only enabled when the Worker is instantiated without {type:'module'}.

Hi @developit
Any chance of having this merged/fixed?