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

How to cancel de previous execution? #118

Open
LorhanSohaky opened this issue Mar 7, 2022 · 1 comment
Open

How to cancel de previous execution? #118

LorhanSohaky opened this issue Mar 7, 2022 · 1 comment
Labels
question Further information is requested

Comments

@LorhanSohaky
Copy link

I'm trying to use fuzzy search in a worker, but I'm having the following error:

[useWorker] You can only run one instance of the worker at a time, if you want to run more than one in parallel, create another instance with the hook useWorker()

Code:

import debounce from 'lodash.debounce'
import { useWorker, WORKER_STATUS } from "@koale/useworker";

const fuseSearch = ({ list, query, limit, options }) => {
  // my fuse search
}

const MyComponent = () => {
  const [search, controller] = useWorker(fuseSearch)
  
  const handleInputChange = debounce(async value => {
    controller.kill()
    
    setLoading(true)
    try {
      const data = await search({ list: fundos, query: value, limit: 10, options })
      setLoading(false)
      setResultados(data)
    } catch (err) {
      if (err?.message) {
        setLoading(false)
        console.error(err)
      }
    }
  }, 300)
}
@LorhanSohaky LorhanSohaky added the question Further information is requested label Mar 7, 2022
@ashish-r
Copy link
Contributor

ashish-r commented May 21, 2022

There is an issue with the kill functionality of the library, I have created a fix for the same. Waiting for the maintainers to review and merge the same.
#122

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants