Web workers and Multi Threading in JS. How are Web Workers different from Promises?

Опубликовано: 30 Сентябрь 2024
на канале: akki
534
31

Web workers bring the multi threading ability to Javascript. Multihtreading is the ability to conjure up different processes ( ie threads ) and run different code bases.

Web Workers are not same as Promises. A Promise code runs in a an asynchronous way..ie Javascript engine will put the code in a promise in a "deferred bag"..whenever there is some free time availble to engine it will start executing the code. The code still runs on the same thread which a users uses to click a button or select some text. If the promise code is long ( or crappy) it will hang the user experience.

This is not the case with Web Workers, as the code is running in a completely different process

#funcWithJS #react #javascript #multiThreading #webWorkers