Skip to content

does not work in nodejs with a worker with dependencies #5

@jobo322

Description

@jobo322

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions