File tree 10 files changed +21
-21
lines changed
10 files changed +21
-21
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const promisify = require('./promisify');
6
6
const readFile = promisify ( fs . readFile ) ;
7
7
8
8
function readTextFile ( filename ) {
9
- let promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
9
+ const promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
10
10
return promise ;
11
11
}
12
12
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const promisify = require('./promisify');
6
6
const readFile = promisify ( fs . readFile ) ;
7
7
8
8
function readTextFile ( filename ) {
9
- let promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
9
+ const promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
10
10
return promise ;
11
11
}
12
12
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const promisify = require('./promisify');
6
6
const readFile = promisify ( fs . readFile ) ;
7
7
8
8
function readTextFile ( filename ) {
9
- let promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
9
+ const promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
10
10
return promise ;
11
11
}
12
12
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ const httpGet = require('./get-json');
4
4
5
5
const baseUrl = 'http://localhost:3000/' ;
6
6
httpGet ( baseUrl ) . then ( ( api ) => {
7
- let promises = [ ] ;
8
- for ( let resource of api . resources ) {
7
+ const promises = [ ] ;
8
+ for ( const resource of api . resources ) {
9
9
promises . push ( httpGet ( baseUrl + resource ) ) ;
10
10
}
11
11
Promise . all ( promises ) . then ( ( values ) => {
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ const async = require('./async');
5
5
6
6
const baseUrl = 'http://localhost:3000/' ;
7
7
async ( function * ( ) {
8
- let api = yield httpGet ( baseUrl ) ;
9
- for ( let resource of api . resources ) {
10
- let data = yield httpGet ( baseUrl + resource ) ;
8
+ const api = yield httpGet ( baseUrl ) ;
9
+ for ( const resource of api . resources ) {
10
+ const data = yield httpGet ( baseUrl + resource ) ;
11
11
console . log ( data ) ;
12
12
}
13
13
} ) ;
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ import httpGet from '../get-json';
5
5
const baseUrl = 'http://localhost:3000/' ;
6
6
7
7
( async ( ) => {
8
- let api = await httpGet ( baseUrl ) ;
9
- for ( let resource of api . resources ) {
10
- let data = await httpGet ( baseUrl + resource ) ;
8
+ const api = await httpGet ( baseUrl ) ;
9
+ for ( const resource of api . resources ) {
10
+ const data = await httpGet ( baseUrl + resource ) ;
11
11
console . log ( data ) ;
12
12
}
13
- } ) ( ) ;
13
+ } ) ( ) ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
module . exports = ( asyncFn ) => {
4
- let generator = asyncFn ( ) ;
4
+ const generator = asyncFn ( ) ;
5
5
let result = generator . next ( ) ;
6
6
7
7
return new Promise ( ( resolve , reject ) => {
8
8
step ( ) ;
9
9
10
10
function step ( ) {
11
- let promise = Promise . resolve ( result . value ) ;
11
+ const promise = Promise . resolve ( result . value ) ;
12
12
13
13
if ( result . done ) {
14
14
resolve ( promise ) ;
Original file line number Diff line number Diff line change @@ -5,20 +5,20 @@ const http = require('http');
5
5
module . exports = ( url ) => {
6
6
return new Promise ( ( resolve , reject ) => {
7
7
http . get ( url , res => {
8
- let code = res . statusCode ;
8
+ const code = res . statusCode ;
9
9
if ( code !== 200 ) {
10
10
return reject ( new Error ( `HTTP status code ${ code } ` ) ) ;
11
11
}
12
12
13
13
res . on ( 'error' , reject ) ;
14
14
15
- let chunks = [ ] ;
15
+ const chunks = [ ] ;
16
16
res . on ( 'data' , chunk => {
17
17
chunks . push ( chunk ) ;
18
18
} ) ;
19
19
20
20
res . on ( 'end' , ( ) => {
21
- let json = Buffer . concat ( chunks ) . toString ( ) ;
21
+ const json = Buffer . concat ( chunks ) . toString ( ) ;
22
22
let object = null ;
23
23
24
24
try {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ module.exports = function promisify(asyncFunction) {
10
10
resolve ( result ) ;
11
11
}
12
12
} ) ;
13
- asyncFunction . apply ( undefined , args ) ;
13
+ asyncFunction ( ... args ) ;
14
14
} ) ;
15
15
} ;
16
16
} ;
Original file line number Diff line number Diff line change @@ -27,21 +27,21 @@ const routes = {
27
27
} ;
28
28
29
29
const server = http . createServer ( ( req , res ) => {
30
- let parsedUrl = url . parse ( req . url ) ;
30
+ const parsedUrl = url . parse ( req . url ) ;
31
31
let path = parsedUrl . pathname ;
32
32
if ( path . endsWith ( '/' ) && path . length > 1 ) {
33
33
path = path . slice ( 0 , - 1 ) ;
34
34
}
35
35
36
- let handler = routes [ path ] ;
36
+ const handler = routes [ path ] ;
37
37
if ( ! handler ) {
38
38
res . writeHead ( 404 ) ;
39
39
res . end ( 'Not found' ) ;
40
40
return ;
41
41
}
42
42
43
43
handler ( req , ( result ) => {
44
- let json = JSON . stringify ( result ) ;
44
+ const json = JSON . stringify ( result ) ;
45
45
res . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ;
46
46
res . end ( json ) ;
47
47
} ) ;
You can’t perform that action at this time.
0 commit comments