Skip to content

Commit ce8c8c9

Browse files
committed
modify example and readme
1 parent 8a3f046 commit ce8c8c9

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
*.sublime*
44
psd
55
thumb
6-
*.log
6+
*.log
7+
yarn.lock

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ const kelp = require('kelp');
1414

1515
const app = kelp();
1616

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);
1932
});
2033

2134
http.createServer(app).listen(3000);

example/index.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
const http = require('http');
2-
const kelp = require('../');
2+
const kelp = require('..');
33

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);
621
});
722

8-
http.createServer(app).listen(3000);
23+
http.createServer(app).listen(3000);

0 commit comments

Comments
 (0)