josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.04k stars 148 forks source link

Imported class is stated to be not defined #445

Closed adokhugi closed 3 months ago

adokhugi commented 3 months ago

In exampleWorker.ts, I import the class OctantBox:

import { OctantBox } from "../spt/OctantBox.ts";

This class is defined as an export class:

export class OctantBox

Then I have the worker function getBoxNodes in which I access OctantBox.

async function getBoxNodes(
  o: OctantBox, 
  maxLevel: number,
  rootEpoch: number,
  bounds: BoundsLatLng | BoundsLatLng[]) {
    const o1 = new OctantBox(o.path, o.octantNumber, o.box, o.children);
    let boxNodes = o1.getNodes(maxLevel, rootEpoch, bounds);
    if (boxNodes) {
      return boxNodes;
    }
    return [];
}

I execute the worker in my main code like this:

  var boxNodePromiseResult = await workerpool.Promise.all(
    octants.map((o) => pool.exec(getBoxNodes, [o, maxLevel, rootEpoch, tileBoundsLatLng]).then(function (result) {
      console.log("OctantBox", o);
    }))
  );

But I get the error message that OctantBox is not defined. What am I doing wrong?

adokhugi commented 3 months ago

My call of the worker function was not correct.

josdejong commented 3 months ago

Ok so I understand the issue is solved. I'll close this issue now.