You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/practice/parallel-letter-frequency/.docs/instructions.append.md
+20-11Lines changed: 20 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,18 @@
1
1
# Instructions append
2
2
3
-
Javascript is single-threaded by nature, so it lacks many of the language features that other languages have in order to handle parallel code execution.
3
+
JavaScript is single-threaded by nature, so it lacks many of the language features that other languages have in order to handle parallel code execution.
4
4
In fact, the only way to achieve "real" parallel code execution is through `Worker threads` (also reffered to as `Web Workers`).
5
5
6
6
Almost always, code that appears to execute in parallel,
7
7
such as `async functions` or `Promises`, will actually execute concurrently instead.
8
-
This is often better, since modern Javascript is optimized for such use,
8
+
This is often better, since modern JavaScript is optimized for such use,
9
9
and you will often see code that "emulates" (or "cheats") parallel execution by the use of `Promise.all()` and other concurrent execution methods.
10
10
11
-
```exercism/caution
11
+
<!-- prettier-ignore -->
12
+
~~~@exercism/caution
12
13
To pass the tests for this exercise, your solution needs to execute _concurrently_ (or in parallel),
13
14
meaning that synchronous solutions (e.g. a simple `for` loop) will not pass.
14
-
```
15
+
~~~
15
16
16
17
## Concurency vs. Parallelism
17
18
@@ -24,26 +25,27 @@ For the sake of completeness, here's a definition for synchronous execution:
24
25
25
26
- Synchronous execution is when a task has to wait for another running task to complete, before it can run.
26
27
27
-
## Parallelism in Javascript
28
+
## Parallelism in JavaScript
28
29
29
-
Even though Javascript by default is single-threaded, there is a way to execute code in parallel fashion.
30
+
Even though JavaScript by default is single-threaded, there is a way to execute code in parallel fashion.
30
31
31
-
If your running javascript in the browser (e.g. in a web app),
32
+
If you are running JavaScript in the browser (e.g. in a web app),
32
33
then the way to achieve parallelism is through the [Web Worker API][mdn-demo].
33
34
As described by MDN:
34
35
35
36
> Web Workers makes it possible to run a script operation in a background thread separate from the main execution thread of an application.
36
37
37
-
On the other hand, if your javascript is running in Node.js, which is Exercism's target runtime,
38
+
On the other hand, if your JavaScript is running in Node.js, which is Exercism's target runtime,
38
39
this same concept is known as [Worker threads][node].
39
40
40
-
```exercism/caution
41
+
<!-- prettier-ignore -->
42
+
~~~@exercism/caution
41
43
Be aware that the implementation of the worker API differs largely between browsers and other JavaScript environments.
42
44
43
45
Make sure to read the documentation for your specific runtime!
44
-
```
46
+
~~~
45
47
46
-
Here's a simple demo of the `Web Worker API` (taken from [here][medium-demo])
48
+
Here's a simple demo of the `Web Worker API` (taken from [Medium][medium-demo])
47
49
48
50
```js
49
51
// main.js
@@ -100,6 +102,13 @@ if (isMainThread) {
100
102
}
101
103
```
102
104
105
+
<!-- prettier-ignore -->
106
+
~~~@exercism/caution
107
+
Currently it is not possible to implement parallelism using the online editor.
108
+
109
+
Please implement `Worker threads` using Node.js locally and submit your solution via CLI!
110
+
~~~
111
+
103
112
As a stretch goal, consider if your implementation can be adapted to make use of `Worker threads`.
0 commit comments