JavaScript Web Workers Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ม.ค. 2025

ความคิดเห็น • 101

  • @DevSage
    @DevSage  3 ปีที่แล้ว +1

    💙 Twitter: twitter.com/realDevSage
    📙 Ebooks: payhip.com/devsage
    💥 Discord: discord.gg/BP8wPv6raA
    👕 Merch: cottonbureau.com/people/devsage

  • @be2wa
    @be2wa 2 ปีที่แล้ว +84

    Your way of explaining is probably the best I've seen on TH-cam. Your video on a certain concept pretty much leaves me with no questions to ask about it.

    • @DevSage
      @DevSage  2 ปีที่แล้ว +13

      This comment made me smile. Yeah I try to set my videos apart by making them as simple as possible, ironically. Some other teachers I've seen on TH-cam are REALLY smart and knowledgeable about programming topics but are lousy communicators so the overall message gets lost and the tutorial becomes of little value.

  • @abhishekpratap05
    @abhishekpratap05 2 ปีที่แล้ว +7

    What if you need web workers to do multiple tasks and in different js files, how will they distinguish between msgs they pass among themselves. Like there is no indication apart from where it's called an instance of worker can have different name, but inside worker.js file how will they distinguish between multiple functions (performing different tasks)

  • @vijay_explorer
    @vijay_explorer 2 ปีที่แล้ว +11

    I love your approach of explaining in a short consice and a simple manner. Thank you now I have an understanding of web workers. ❤️

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      You're very welcome!

  • @ashishagarwal3514
    @ashishagarwal3514 2 ปีที่แล้ว +18

    Wow this is a great tutorial. I have seen like 20 videos of you in last 2-3 hours, your explanations are super easy to understand. Can you please also make a video on use cases distinguishing web worker vs service worker and web scokets?
    I am confused which one to be used for what type of use cases?

  • @anouarnouri2111
    @anouarnouri2111 3 ปีที่แล้ว +9

    I've never heard about web workers before, this is interesting, thank you so much.

    • @DevSage
      @DevSage  3 ปีที่แล้ว +1

      You're welcome!

  • @yinonelbaz5309
    @yinonelbaz5309 2 ปีที่แล้ว +1

    Feels lucky I discovered your channel

  • @capnmorgs6195
    @capnmorgs6195 3 ปีที่แล้ว +5

    A lot of these videos have been super helpful! Good length, good explanations. Thanks dude! Keep it up!

    • @DevSage
      @DevSage  3 ปีที่แล้ว

      Glad you like them!

  • @MahmoudKhudairi
    @MahmoudKhudairi 2 ปีที่แล้ว +2

    Thank you man, it was an intro of basics , but it was useful, it introduced me to the main concept of Web Worker API

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      No problem

  • @paulbocostudio
    @paulbocostudio 2 ปีที่แล้ว +2

    Best explanation I've heard yet. I'm ready to code some workers now. 👍

  • @divijakatakam2803
    @divijakatakam2803 2 ปีที่แล้ว +1

    this is so helpful especially for a beginner

  • @VuNguyen-ni4ex
    @VuNguyen-ni4ex 3 ปีที่แล้ว +7

    Please do a video explain about service worker :) Great video by the way

    • @DevSage
      @DevSage  3 ปีที่แล้ว

      I will put it on my radar

    • @gradientMesh
      @gradientMesh 3 ปีที่แล้ว +1

      Yes, please!

  • @Crevulus
    @Crevulus 2 ปีที่แล้ว +7

    Great explainer video. Loved the way you demonstrated. For your next videos can I request some things I often confuse with "web workers"?
    Service workers
    Web sockets
    Web components

  • @pmsoxllc9501
    @pmsoxllc9501 2 ปีที่แล้ว +1

    Thanks!

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      I really appreciate that Omar!

  • @0xlkda
    @0xlkda 2 ปีที่แล้ว +1

    great, I wonder if i can inject worker as code from server to hide my logic from public but still using client computation power

  • @vatsalyasinghi438
    @vatsalyasinghi438 3 ปีที่แล้ว

    Is it possible to pass the function and the params to the worker file and return the result ? So it can be versatile..

  • @gameplayerita5694
    @gameplayerita5694 2 ปีที่แล้ว

    but what happen if I tell the worker to do some heavy stuff before it has finished previous heavy stuff?

  • @xmaxfuture
    @xmaxfuture 2 ปีที่แล้ว

    you just earned yourself a subscriber. well done!

  • @harshgupta5799
    @harshgupta5799 2 ปีที่แล้ว +1

    Nice example demo. Works perfectly.

  • @phxm7853
    @phxm7853 2 ปีที่แล้ว +1

    Simple, Short and Clean 👍👍👍

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      Thanks!

  • @itzazeez6662
    @itzazeez6662 2 ปีที่แล้ว +1

    Short and to the point. Great explanation thanks man. new subscriber notification up.

  • @gradientMesh
    @gradientMesh 3 ปีที่แล้ว +3

    Very clearly explained! Thank you for sharing.

    • @DevSage
      @DevSage  3 ปีที่แล้ว

      You're welcome!

  • @oz4549
    @oz4549 2 ปีที่แล้ว

    You Sir are a true hero. Thanks for this!

  • @ashimov1970
    @ashimov1970 2 ปีที่แล้ว +1

    super awesome explanation, man 👍👏

  • @antonismavrakis5199
    @antonismavrakis5199 2 ปีที่แล้ว +1

    Good work man, it really helped

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      Glad it helped

  • @easonhuang4031
    @easonhuang4031 2 ปีที่แล้ว +1

    how to use it in ReactJS project?

  • @furkannarin2844
    @furkannarin2844 2 ปีที่แล้ว +1

    Hey man thanks for the tutorial. I am getting an error for Worker constructor when I use it like this. It is not defined for me. Also, if I use the new syntax where you put in url in the constructor like this:
    ```
    new Worker(new URL('path'), import.meta.url)
    ```
    I dont get any errors like this but in this case, when I specify the onmessage function in the worker script, self and onmessage are both undefined again. Any ideas?

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      The first parameter of the Worker constructor should be a string

    • @furkannarin2844
      @furkannarin2844 2 ปีที่แล้ว

      @@DevSage it is a string :/

  • @H2daB
    @H2daB 3 ปีที่แล้ว +2

    Thank you for explaining this. It was very helpful!

    • @DevSage
      @DevSage  3 ปีที่แล้ว

      Glad it was helpful!

  • @pixelloopy
    @pixelloopy 2 ปีที่แล้ว +2

    Brilliantly explained, thank you!

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      Glad it was helpful!

  • @saikarthik658
    @saikarthik658 2 ปีที่แล้ว +1

    Very lucidly explained!! Thank you....

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      You're welcome!

  • @depralexcrimson
    @depralexcrimson 2 ปีที่แล้ว +2

    So very well explained, thanks.

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      No problem

  • @33lightheart
    @33lightheart 2 ปีที่แล้ว +1

    Great video thanks! that helped me to understand web workers for the first time.
    Could you please also make a video about promise, I still don't know if there is any background work going on with promises,
    or is await promise also being performed on the main thread, blocking it until the promise is finished?

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      I do have videos on Promises and also await/async. Yes when you await a Promise you're effectively blocking the main thread of execution until that promise resolves (or rejects)

  • @hanifkhan2821
    @hanifkhan2821 2 ปีที่แล้ว +1

    Simple and Perfect
    Keep it up!!

  • @王冠信-o1c
    @王冠信-o1c 2 ปีที่แล้ว

    clear and informative with an example. Thank you so much.

  • @martinemanuel8239
    @martinemanuel8239 2 ปีที่แล้ว +1

    Amazing explanation man !!

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      Appreciate it!

  • @alexanderm6187
    @alexanderm6187 3 ปีที่แล้ว +2

    What the perfect explanation! Thank you for that! :)
    So technically said workers are calculated on a "virtual" threads of JS-engine, not on real CPU threads/cores?

    • @DevSage
      @DevSage  3 ปีที่แล้ว +3

      Glad it helped! According to the Mozilla docs, workers are spawned using "real OS-level threads"
      developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#about_thread_safety

    • @alexanderm6187
      @alexanderm6187 3 ปีที่แล้ว +2

      @@DevSage that's nice to know it! Thank you for the reply :)

  • @mohammadreza404
    @mohammadreza404 2 ปีที่แล้ว +1

    That was sooooooooo clear and straight .
    Thank you very much

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      You're welcome!

  • @sadeqmousawi140
    @sadeqmousawi140 2 ปีที่แล้ว +1

    Nice job boy , Thank you so much 🌹

  • @darz_k.
    @darz_k. 2 ปีที่แล้ว +1

    Yep - great stuff - subscribed.

  • @ChickenMaster7
    @ChickenMaster7 2 ปีที่แล้ว

    can I use it in react?

  • @aaf2011
    @aaf2011 2 ปีที่แล้ว +3

    Hi patrick, so web workers seems to be look like (async/await or promises) concept. eventually we defer specific task/s since it takes long time of response while in the same time we complete the other tasks so that we don't waste time in waiting.
    It is obvious that the main goal of these techniques is to control the outcome and performance of the application but I would like to see more details on the web workers and async/await concepts in real life example.
    Sync = Action A .. wait for the results of (A)
    Async = Action A .... wait for the results of (A) and keep doing other actions of (B), (C) and(D)
    This is how I understood Sync/Async/Web Workers .... Am I right ?

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      Yes, the underlying idea is all the same. Synchronous work is "blocking" while asynchronous work is "non-blocking"

  • @osvaldocarrillo1361
    @osvaldocarrillo1361 2 ปีที่แล้ว

    Thank you. Very well explained 👍

  • @ignjat4123
    @ignjat4123 2 ปีที่แล้ว +1

    Great video. Thanks a lot, man

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      You're welcome

  • @ny9113
    @ny9113 2 ปีที่แล้ว +1

    Great explanation !

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      Thank you!

  • @jerecrack12gamer7
    @jerecrack12gamer7 2 ปีที่แล้ว

    i couldnt finish reading it but the first 2 sentences were inspirin LMAO

  • @СтаниславОкулов-о2ч
    @СтаниславОкулов-о2ч 2 ปีที่แล้ว +1

    Thank you for your work!

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      My pleasure!

  • @yadneshkhode3091
    @yadneshkhode3091 3 ปีที่แล้ว +1

    Awesome man 👍

    • @DevSage
      @DevSage  3 ปีที่แล้ว

      Thanks

  • @quangpham-qs5oo
    @quangpham-qs5oo 2 ปีที่แล้ว +1

    thank you so much for your sharing.

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      You're welcome!

  • @honeyresearch
    @honeyresearch 2 ปีที่แล้ว +1

    great video thanks! :)

  • @Calebwaldner
    @Calebwaldner 2 ปีที่แล้ว +1

    Great video

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      Thanks Caleb

  • @rajastylez
    @rajastylez 2 ปีที่แล้ว +1

    Solid example

  • @pupfriend
    @pupfriend 3 ปีที่แล้ว +1

    Awesome!!

    • @DevSage
      @DevSage  3 ปีที่แล้ว

      Thanks!

  • @stoncjoesperanto8632
    @stoncjoesperanto8632 2 ปีที่แล้ว

    Not readable on smartphones :'-(

  • @forzahorizon8560
    @forzahorizon8560 2 ปีที่แล้ว

    Thank you!

  • @mirceahanghiuc4447
    @mirceahanghiuc4447 2 ปีที่แล้ว +1

    Super cool

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      Thanks Mircea!

  • @CrazyCodingChannel
    @CrazyCodingChannel 3 ปีที่แล้ว +1

    Very helpful, thnx

    • @DevSage
      @DevSage  3 ปีที่แล้ว

      No problem!

  • @rajansidhu5912
    @rajansidhu5912 2 ปีที่แล้ว

    Thank you :)

  • @yurapekach7550
    @yurapekach7550 2 ปีที่แล้ว

    Thank you)

  • @toanho7462
    @toanho7462 2 ปีที่แล้ว

    nice explain

  • @rxdrik1ng966
    @rxdrik1ng966 2 ปีที่แล้ว

    Nice

  • @fripickbot4043
    @fripickbot4043 2 ปีที่แล้ว +1

    Great. And please stop repeating that javaScript is "single threaded" JavaScript is not single threaded. This is only confusing new comers.

    • @DevSage
      @DevSage  2 ปีที่แล้ว +1

      So are you saying that the developers at Mozilla are incorrect? developer.mozilla.org/en-US/docs/Web/JavaScript

  • @tharidhuheshan
    @tharidhuheshan 2 ปีที่แล้ว

    Classic

  • @divijakatakam2803
    @divijakatakam2803 2 ปีที่แล้ว +1

    this is so helpful especially for a beginner

  • @abat_dauletbaev
    @abat_dauletbaev 2 ปีที่แล้ว +1

    Great explanation!

    • @DevSage
      @DevSage  2 ปีที่แล้ว

      Thanks!