Skip to content

Commit

Permalink
chore: working on chapter 4
Browse files Browse the repository at this point in the history
  • Loading branch information
lmammino committed Oct 5, 2024
1 parent fd09cbf commit bc9d8a0
Show file tree
Hide file tree
Showing 28 changed files with 4,271 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { spider } from './spider.js'
spider(process.argv[2], (err, filename, downloaded) => {
if (err) {
console.error(err)
} else if (downloaded) {
process.exit(1)
}

if (downloaded) {
console.log(`Completed the download of "${filename}"`)
} else {
console.log(`"${filename}" was already downloaded`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Refactored version of web spider that cleans up callback hell.
Install the necessary dependencies with `npm install` and then run:

```bash
node spider-cli.js https://loige.co
node spider-cli.js https://loige.co 3
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { spider } from './spider.js'
spider(process.argv[2], (err, filename, downloaded) => {
if (err) {
console.error(err)
} else if (downloaded) {
process.exit(1)
}

if (downloaded) {
console.log(`Completed the download of "${filename}"`)
} else {
console.log(`"${filename}" was already downloaded`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function download(url, filename, cb) {
if (err) {
return cb(err)
}
cb(null)
cb(null, content)
})
})
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 03-sequential-execution

Simple example that demonstrates sequential tasks using callbacks

## Run

Run:

```bash
node index.js
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function asyncOperation(cb) {
process.nextTick(cb)
}

function task1(cb) {
asyncOperation(() => {
task2(cb)
})
}

function task2(cb) {
asyncOperation(() => {
task3(cb)
})
}

function task3(cb) {
asyncOperation(() => {
cb() // finally executes the callback
})
}

task1(() => {
// executed when task1, task2 and task3 are completed
console.log('tasks 1, 2 and 3 executed')
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "03-sequential-execution",
"version": "1.0.0",
"description": "Simple example that demonstrates sequential tasks using callbacks",
"engines": {
"node": ">=22"
},
"engineStrict": true,
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 04-web-spider-v2

Web spider example to demonstrate sequential iteration

## Run

Install the necessary dependencies with `npm install` and then run:

```bash
node spider-cli.js https://loige.co
```
Loading

0 comments on commit bc9d8a0

Please sign in to comment.