Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TerminateWorker typing and errors #208

Closed
studiosciences opened this issue Jan 10, 2023 · 1 comment · Fixed by #274
Closed

TerminateWorker typing and errors #208

studiosciences opened this issue Jan 10, 2023 · 1 comment · Fixed by #274
Labels

Comments

@studiosciences
Copy link

studiosciences commented Jan 10, 2023

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();
    };
@jlaneve
Copy link

jlaneve commented Jan 10, 2023

+1 on this, was looking to do something similar but couldn't figure it out!

Eddykasp added a commit that referenced this issue Apr 16, 2024
 #208 Add worker termination conditions and method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants