File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const promisify = require('./promisify');
66const readFile = promisify ( fs . readFile ) ;
77
88function readTextFile ( filename ) {
9- let promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
9+ const promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
1010 return promise ;
1111}
1212
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const promisify = require('./promisify');
66const readFile = promisify ( fs . readFile ) ;
77
88function readTextFile ( filename ) {
9- let promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
9+ const promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
1010 return promise ;
1111}
1212
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const promisify = require('./promisify');
66const readFile = promisify ( fs . readFile ) ;
77
88function readTextFile ( filename ) {
9- let promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
9+ const promise = readFile ( filename ) . then ( data => data . toString ( ) ) ;
1010 return promise ;
1111}
1212
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ const httpGet = require('./get-json');
44
55const baseUrl = 'http://localhost:3000/' ;
66httpGet ( baseUrl ) . then ( ( api ) => {
7- let promises = [ ] ;
8- for ( let resource of api . resources ) {
7+ const promises = [ ] ;
8+ for ( const resource of api . resources ) {
99 promises . push ( httpGet ( baseUrl + resource ) ) ;
1010 }
1111 Promise . all ( promises ) . then ( ( values ) => {
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ const async = require('./async');
55
66const baseUrl = 'http://localhost:3000/' ;
77async ( 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 ) ;
1111 console . log ( data ) ;
1212 }
1313} ) ;
Original file line number Diff line number Diff line change @@ -5,9 +5,9 @@ import httpGet from '../get-json';
55const baseUrl = 'http://localhost:3000/' ;
66
77( 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 ) ;
1111 console . log ( data ) ;
1212 }
13- } ) ( ) ;
13+ } ) ( ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
33module . exports = ( asyncFn ) => {
4- let generator = asyncFn ( ) ;
4+ const generator = asyncFn ( ) ;
55 let result = generator . next ( ) ;
66
77 return new Promise ( ( resolve , reject ) => {
88 step ( ) ;
99
1010 function step ( ) {
11- let promise = Promise . resolve ( result . value ) ;
11+ const promise = Promise . resolve ( result . value ) ;
1212
1313 if ( result . done ) {
1414 resolve ( promise ) ;
Original file line number Diff line number Diff line change @@ -5,20 +5,20 @@ const http = require('http');
55module . exports = ( url ) => {
66 return new Promise ( ( resolve , reject ) => {
77 http . get ( url , res => {
8- let code = res . statusCode ;
8+ const code = res . statusCode ;
99 if ( code !== 200 ) {
1010 return reject ( new Error ( `HTTP status code ${ code } ` ) ) ;
1111 }
1212
1313 res . on ( 'error' , reject ) ;
1414
15- let chunks = [ ] ;
15+ const chunks = [ ] ;
1616 res . on ( 'data' , chunk => {
1717 chunks . push ( chunk ) ;
1818 } ) ;
1919
2020 res . on ( 'end' , ( ) => {
21- let json = Buffer . concat ( chunks ) . toString ( ) ;
21+ const json = Buffer . concat ( chunks ) . toString ( ) ;
2222 let object = null ;
2323
2424 try {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ module.exports = function promisify(asyncFunction) {
1010 resolve ( result ) ;
1111 }
1212 } ) ;
13- asyncFunction . apply ( undefined , args ) ;
13+ asyncFunction ( ... args ) ;
1414 } ) ;
1515 } ;
1616} ;
Original file line number Diff line number Diff line change @@ -27,21 +27,21 @@ const routes = {
2727} ;
2828
2929const server = http . createServer ( ( req , res ) => {
30- let parsedUrl = url . parse ( req . url ) ;
30+ const parsedUrl = url . parse ( req . url ) ;
3131 let path = parsedUrl . pathname ;
3232 if ( path . endsWith ( '/' ) && path . length > 1 ) {
3333 path = path . slice ( 0 , - 1 ) ;
3434 }
3535
36- let handler = routes [ path ] ;
36+ const handler = routes [ path ] ;
3737 if ( ! handler ) {
3838 res . writeHead ( 404 ) ;
3939 res . end ( 'Not found' ) ;
4040 return ;
4141 }
4242
4343 handler ( req , ( result ) => {
44- let json = JSON . stringify ( result ) ;
44+ const json = JSON . stringify ( result ) ;
4545 res . writeHead ( 200 , { 'Content-Type' : 'application/json' } ) ;
4646 res . end ( json ) ;
4747 } ) ;
You can’t perform that action at this time.
0 commit comments