/**
 * 执行动态js
 * @param code 代码
 * @param param 参数
 * @returns promise
 */
export const cllJsCode = (code: string, param: string): Promise<any> => {
  
  return new Promise((resove, reject) => {
    // 生成一份new webwork
    const blob = new Blob([`
      self.onmessage = function(e) {
        self.postMessage((${code}).call(null, e.data));
      }
    `], { type: 'application/javascript' });

    const worker = new Worker(URL.createObjectURL(blob));
    // 向webwork发送消息
    worker.postMessage(JSON.parse(param));
    worker.onmessage = (e) => {
      worker.terminate();
      resove(e.data);
    }
    worker.onerror = (e) => {
      worker.terminate();
      reject(e);
    }
  });
}