ework icon indicating copy to clipboard operation
ework copied to clipboard

does not work in nodejs with a worker with dependencies

Open jobo322 opened this issue 4 years ago • 1 comments

I'm trying to use a worker comes from a separated file, the code seems like

import { readFileSync, writeFileSync } from 'fs';
import { join } from 'path';

import parseSDF from './parseSDF';

export default function processFile(filename) {
  let sdfText = readFileSync(filename, 'utf8');
  let results = parseSDF(sdfText);

  let hoses = [];
  for (let result of results) {
   hoses.push(result);
  }

  writeFileSync(filename.replace('.sdf', '.json'), JSON.stringify(hoses));
}

the code where I use ework seems like

import { Ework } from 'ework';
import workerFunction from 'worker_path';

async function fun() {
  let files = readdirSync(join(__dirname, '../output')).filter((file) =>
    file.match(/sdf$/),
  );
  const workers = new Ework(processFile);
  const result = await workers.execute(join(__dirname, '../output', files[0]));
}

fun();

but when I try to execute a worker it throw an error that 'readFileSync' is not defined.

am I doing something wrong?

jobo322 avatar Jun 29 '21 17:06 jobo322

We do not maintain this project anymore. I recommend to use piscina if you want this kind of functionality in Node.js: https://github.com/piscinajs/piscina

targos avatar Jun 29 '21 17:06 targos