Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
Is it possible to delegate a single function call, to a WebWorker?

I have some existing code(running in the browser), that follows a certain interface, which I do not want to break/refactor.

There's a sequence of function calls. One of those functions, which isn't under my control(comes from some library), performs heavy calculations, that freeze the main thread, rendering the UI useless for about 40 seconds.

My idea is to use a WebWorker of course. Problem is, that from the examples i see- a WebWorker requires its own isolated script, that communicates with the main thread via "messages". Refactoring my code to fit this "scheme", would be tedious. I'll give a simplified example to what I want to achieve:

class MySimplifiedFacade{
    consturctor(){
        ...
    }

    someLightMethod(params){
        //Do something light
    }

    //THIS IS THE FUNCTION I WOULD LIKE TO SOMEHOW ISOLATE INTO A WEBWORKER
    veryHeavyCalculations(params){
        someExternalLibrary.heavySynchronousCalculation(params)
    }
}

The only thing in the sequence of actions, that actually requires a WebWorker, is this one function called "veryHeavyCalculations" in the example.

Is it possible to somehow isolate a specific "piece of code" inside a WebWorker? Problem is, according to my understanding, is that any thing I pass to a WebWorker via messages, must be "serializable", whereas in my case I would need to pass a reference to some existing object.

Any ideas?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda