Difference between Javascript async functions and Web workers?

后端 未结 6 1488
南笙
南笙 2021-02-05 06:53

Threading-wise, what\'s the difference between web workers and functions declared as

async function xxx()
{
}

?

I am aware web worker

6条回答
  •  无人及你
    2021-02-05 07:40

    I want to add my own answer to my question, with the understanding I gathered through all the other people's answers:

    Ultimately, all but web workers, are glorified callbacks. Code in async functions, functions called through promises, functions called through setInterval and such - all get executed in the main thread with a mechanism akin to context switching. No parallelism exists at all.

    True parallel execution with all its advantages and pitfalls, pertains to webworkers and webworkers alone.

    (pity - I thought with "async functions" we finally got streamlined and "inline" threading)

提交回复
热议问题