File tree 3 files changed +36
-7
lines changed
3 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ node_modules
3
3
* .sublime *
4
4
psd
5
5
thumb
6
- * .log
6
+ * .log
7
+ yarn.lock
Original file line number Diff line number Diff line change @@ -14,8 +14,21 @@ const kelp = require('kelp');
14
14
15
15
const app = kelp ();
16
16
17
- app .use (function (req , res , next ){
18
- res .end (' hello!' );
17
+ const sleep = (n = 1 ) =>
18
+ new Promise (done => setTimeout (done, n * 1e3 ));
19
+
20
+ app .use (async (req , res , next ) => {
21
+ console .log (1 );
22
+ await next ();
23
+ console .log (2 );
24
+ });
25
+
26
+ app .use (async (req , res , next ) => {
27
+ console .log (3 );
28
+ await sleep ();
29
+ res .end (` hello world` );
30
+ await next ();
31
+ console .log (4 );
19
32
});
20
33
21
34
http .createServer (app).listen (3000 );
Original file line number Diff line number Diff line change 1
1
const http = require ( 'http' ) ;
2
- const kelp = require ( '../ ' ) ;
2
+ const kelp = require ( '..' ) ;
3
3
4
- const app = kelp ( function ( req , res ) {
5
- res . end ( 'test' ) ;
4
+ const app = kelp ( ) ;
5
+
6
+ const sleep = ( n = 1 ) =>
7
+ new Promise ( done => setTimeout ( done , n * 1e3 ) ) ;
8
+
9
+ app . use ( async ( req , res , next ) => {
10
+ console . log ( 1 ) ;
11
+ await next ( ) ;
12
+ console . log ( 2 ) ;
13
+ } ) ;
14
+
15
+ app . use ( async ( req , res , next ) => {
16
+ console . log ( 3 ) ;
17
+ await sleep ( ) ;
18
+ res . end ( `hello world` ) ;
19
+ await next ( ) ;
20
+ console . log ( 4 ) ;
6
21
} ) ;
7
22
8
- http . createServer ( app ) . listen ( 3000 ) ;
23
+ http . createServer ( app ) . listen ( 3000 ) ;
You can’t perform that action at this time.
0 commit comments