Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!