Skip to content

Synchronous execution #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 22 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ function compression (options) {
var _on = res.on
var _write = res.write

var flushCB = function flushCB () {
stream.flush()
}

var endCB = function endCB () {
stream.end()
}

// flush
res.flush = function flush () {
if (stream) {
stream.flush()
// call write and pass flushCB to force synchronous behavior
stream.write('', flushCB)
}
}

Expand Down Expand Up @@ -110,9 +119,10 @@ function compression (options) {
ended = true

// write Buffer for Node.js 0.8
// call write and pass endCB to force synchronous behavior
return chunk
? stream.end(new Buffer(chunk, encoding))
: stream.end()
? stream.write(new Buffer(chunk, encoding), endCB)
: stream.write('', endCB)
}

res.on = function on (type, listener) {
Expand Down