Skip to content

TerminateWorker typing and errors #208

@studiosciences

Description

@studiosciences

terminateWorker is documented in the README, but not included in the types. It can also error if the worker is not currently defined.

Expected behavior

  • elk.terminateWorker() is a documented in types
  • elk.terminateWorker() will not error if the worker is not defined (Not sure of the circumstances if this).

Screenshots
If applicable, add screenshots to help explain your problem.

ELK Version
0.8.2

Additional context
I want to terminate the layout rendering if the graph changes again before the rendering is complete. I'm not 100% sure that calling terminateWorker will not create a

  useEffect(() => {
    const elk = new ELK({
      workerUrl: webWorkerUrl,
    });

    elk
      .layout(elkInput)
      .then((elkOutput) => {
        // ...consume the elkOutput
      })
      .catch((err) => {
        throw new Error(err);
      });

    // Cancel the current job when input changes.
    return elk.terminateWorker; // <-- HERE
  }, [elkInput, webWorkerUrl]);

Workaround

    // Cancel the current job when input changes.
    return () => {
      // @ts-expect-error function is not documented
      if (elk.worker) elk.terminateWorker();
    };

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions