a simple bigpipe impl with koa 2.x
npm i -S koa-bigpipe
app.use(require('koa-bigpipe'))
write chunk to browser. if chunk == null or undefined, it will end.
end response
let count = ctx.chunks.length
const Koa = require('koa')
const app = new Koa()
const sleep = ms => new Promise(r => setTimeout(r, ms))
app.use(require('.'))
// response
app.use(ctx => {
// ctx.body = 'Hello Koa'
ctx.write('loading...<br>')
return sleep(2000).then(function(){
ctx.write(`timer: 2000ms<br>`)
return sleep(5000)
}).then(function(){
ctx.write(`timer: 5000ms<br>`)
}).then(function(){
ctx.end()
})
})
app.listen(3000)
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)i5ting
[email protected]
issue
this repo is released under the MIT License.