Skip to content

Commit 7ed7901

Browse files
committed
update grammar
1 parent e2edd1f commit 7ed7901

4 files changed

+9
-15
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.DS_Store
1+
.DS_Store
2+
test.md
3+
generate-index.js

chapters/ch01-what-is-a-web-server-anyway.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
[![Read Prev](/assets/imgs/prev.png)](/Readme.md)
32

43
# What the hell is a web server any way?

chapters/ch03-working-with-files.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ async function read_file() {
694694
try {
695695
const file_handle = await fs.open("./index.js");
696696
const stream = file_handle.readLines();
697-
697+
698698
// we'll get to this syntax in a bit
699699
for await (const line of stream) {
700700
console.log("Reading line of length %d -> %s", line.length, line);
@@ -717,13 +717,14 @@ Reading line of length 12 -> read_file();
717717

718718
Notice that we get rid of all those options since they are already set to default values for our convenience. Only specify them if you wish to choose values other than the defaults.
719719

720-
## A small primer to `for..of` and `for await..of` in javascript
720+
## A small primer on `for..of` and `for await..of` in javascript
721721

722722
### `for..of`
723723

724724
The **`for..of`** loop is a JavaScript feature that provides an easy and straightforward way to go through elements in an array, string, or other [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) objects. It makes it simpler to iterate through each item without the need to manage the loop's index or length manually.
725725

726726
Let's look at the syntax:
727+
727728
```js
728729
for (const element of iterable) {
729730
// Code to be executed for each element

chapters/ch04.3-capturing-metadata.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ Let's add the following in our `#log` method of the `Logger` class:
162162

163163
class Logger {
164164
...
165-
165+
166166
async #log(message, log_level) {
167167
if (log_level < this.#config.level || !this.#log.file_handle.fd) {
168168
return;
169169
}
170-
170+
171171
/* New code inserted */
172172
let stack_trace;
173173
try {
@@ -177,7 +177,7 @@ class Logger {
177177
}
178178
console.log(stack_trace)
179179
/* New code ends */
180-
180+
181181
await this.#log_file_handle.write(log_message);
182182
}
183183

@@ -204,8 +204,6 @@ async function main() {
204204
}
205205

206206
main()
207-
208-
209207
```
210208

211209
This outputs
@@ -395,8 +393,6 @@ function super_nested(logger) {
395393
}
396394

397395
main()
398-
399-
400396
```
401397

402398
The log file shows the following -
@@ -405,8 +401,6 @@ The log file shows the following -
405401
[2023-08-19T19:11:51.888Z] [CRITICAL]: main (/Users/ihtmeet/Code/logtard/test.js:11:12) From the main() function
406402
[2023-08-19T19:11:51.888Z] [CRITICAL]: nested_func (/Users/ishtmeet/Code/logtard/test.js:16:12) From the nested_func() function
407403
[2023-08-19T19:11:51.888Z] [CRITICAL]: super_nested (/Users/ishtmeet/Code/logtard/test.js:21:12) From the super_nested() function
408-
409-
410404
```
411405

412406
This all seems to work pretty well. We now have helpful logs. However, before we start using this logging library in our personal projects, there are a lot of things that need to be taken care of. This includes logging crashes, handling SIGINT and SIGTERM signals, as well as properly utilizing the file_handle.
@@ -416,5 +410,3 @@ We'll take care of this in the next chapter.
416410
> The code for the entire chapter can be found [at the code/chapter_04.3 directory](/code/chapter_04.3/)
417411
418412
![](https://uddrapi.com/api/img?page=ch04.3)
419-
420-

0 commit comments

Comments
 (0)