I am building a tiny library that interfaces with the Canvas API through functional means.
Some functions may take too long – either due to their complexity – or a programming error (infinite loop).
If possible, how would I be able to detect that the main thread is being blocked?
Obviously JavaScript is single-threaded so is there a way to go around this?
I never had experience with Web Workers, this primary issue needs to be resolved as I’m writing a small benchmark utility (for development) and it needs to terminate a task if it exceeds a certain execution time threshold. A while loop with a counter can’t help here if the function gets into an infinite loop (right?)
JavaScript is single-threaded, I’m assuming Web Workers could resolve the problem I’m facing outlined above.
My experience with Web Workers is limited, and don’t know how easy it is to apply to resolve the problem.
Nurudin Imširović is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1