Skip to content

Commit

Permalink
docs(learn): Migrate the Don't Block the Event Loop (or the Worker Po…
Browse files Browse the repository at this point in the history
…ol) to the learn (#6351)

Co-authored-by: Claudio W <[email protected]>
  • Loading branch information
officeneerajsaini and ovflowd authored Feb 23, 2024
1 parent f1b6e16 commit 6f84df9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
3 changes: 2 additions & 1 deletion i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"theNodejsEventLoop": "The Node.js Event Loop",
"theNodejsEventEmitter": "The Node.js Event Emitter",
"understandingProcessnexttick": "Understanding process.nextTick()",
"understandingSetimmediate": "Understanding setImmediate()"
"understandingSetimmediate": "Understanding setImmediate()",
"dontBlockTheEventLoop": "Don't Block the Event Loop"
}
},
"manipulatingFiles": {
Expand Down
4 changes: 4 additions & 0 deletions navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@
"understandingSetimmediate": {
"link": "/learn/asynchronous-work/understanding-setimmediate",
"label": "components.navigation.learn.asynchronousWork.links.understandingSetimmediate"
},
"dontBlockTheEventLoop": {
"link": "/learn/asynchronous-work/dont-block-the-event-loop",
"label": "components.navigation.learn.asynchronousWork.links.dontBlockTheEventLoop"
}
}
},
Expand Down
12 changes: 0 additions & 12 deletions pages/en/guides/index.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Don't Block the Event Loop (or the Worker Pool)
layout: docs.hbs
layout: learn.hbs
---

# Don't Block the Event Loop (or the Worker Pool)
Expand Down Expand Up @@ -270,12 +270,12 @@ If your server manipulates JSON objects, particularly those from a client, you s
Example: JSON blocking. We create an object `obj` of size 2^21 and `JSON.stringify` it, run `indexOf` on the string, and then JSON.parse it. The `JSON.stringify`'d string is 50MB. It takes 0.7 seconds to stringify the object, 0.03 seconds to indexOf on the 50MB string, and 1.3 seconds to parse the string.

```js
var obj = { a: 1 };
var niter = 20;
let obj = { a: 1 };
let niter = 20;

var before, str, pos, res, took;
let before, str, pos, res, took;

for (var i = 0; i < niter; i++) {
for (let i = 0; i < niter; i++) {
obj = { obj1: obj, obj2: obj }; // Doubles in size each iter
}

Expand Down Expand Up @@ -325,7 +325,7 @@ Example 2: Partitioned average, each of the `n` asynchronous steps costs `O(1)`.
```js
function asyncAvg(n, avgCB) {
// Save ongoing sum in JS closure.
var sum = 0;
let sum = 0;
function help(i, cb) {
sum += i;
if (i == n) {
Expand All @@ -340,7 +340,7 @@ function asyncAvg(n, avgCB) {

// Start the helper, with CB to call avgCB.
help(1, function (sum) {
var avg = sum / n;
let avg = sum / n;
avgCB(avg);
});
}
Expand Down
4 changes: 4 additions & 0 deletions redirects.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@
"source": "/:locale/guides/event-loop-timers-and-nexttick",
"destination": "/:locale/learn/asynchronous-work/event-loop-timers-and-nexttick"
},
{
"source": "/:locale/guides/dont-block-the-event-loop",
"destination": "/:locale/learn/asynchronous-work/dont-block-the-event-loop"
},
{
"source": "/:locale/get-involved",
"destination": "/:locale/about/get-involved"
Expand Down

0 comments on commit 6f84df9

Please sign in to comment.