async-writer
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -46,6 +46,6 @@ /* | ||
function onProxy(asyncWriter, type, event, callback) { | ||
var attributes = asyncWriter.attributes; | ||
var global = asyncWriter.global; | ||
if (event === 'end') { | ||
if (attributes.ended) { | ||
if (global.ended) { | ||
callback(); | ||
@@ -56,3 +56,3 @@ return asyncWriter; | ||
var events = attributes.events; | ||
var events = global.events; | ||
events[type](event, callback); | ||
@@ -131,14 +131,12 @@ return asyncWriter; | ||
function AsyncWriter(writer, attributes) { | ||
this.attributes = attributes || (attributes = {}); | ||
function AsyncWriter(writer, global) { | ||
this.global = this.attributes /* legacy */ = global || (global = {}); | ||
this._af = this._prevAF = this._parentAF = null; | ||
this._isSync = false; | ||
if (!attributes.events) { | ||
attributes.events = new EventEmitter(); | ||
if (!global.events) { | ||
global.events = new EventEmitter(); | ||
} | ||
if (!attributes.async) { | ||
if (!global.async) { | ||
if (writer && writer.end) { | ||
@@ -150,3 +148,3 @@ this.on('end', function() { | ||
attributes.async = { | ||
global.async = { | ||
remaining: 0, | ||
@@ -177,6 +175,6 @@ ended: false, | ||
getAttributes: function () { | ||
return this.attributes; | ||
return this.global; | ||
}, | ||
getAttribute: function (name) { | ||
return this.attributes[name]; | ||
return this.global[name]; | ||
}, | ||
@@ -199,12 +197,9 @@ write: function (str) { | ||
var oldWriter = this.writer; | ||
try { | ||
this.writer = newWriter; | ||
func.call(thisObj); | ||
} finally { | ||
this.writer = oldWriter; | ||
} | ||
this.writer = newWriter; | ||
func.call(thisObj); | ||
this.writer = oldWriter; | ||
}, | ||
createNestedContext: function (writer) { | ||
var _this = this; | ||
var child = new AsyncWriter(writer, _this.attributes); | ||
var child = new AsyncWriter(writer, _this.global); | ||
// Keep a reference to the original stream. This was done because when | ||
@@ -265,3 +260,3 @@ // rendering to a response stream we can get access to the request/response | ||
var async = _this.attributes.async; | ||
var async = _this.global.async; | ||
@@ -315,9 +310,9 @@ var timeout; | ||
emit: function(event) { | ||
var attributes = this.attributes; | ||
var global = this.global; | ||
if (event === 'end') { | ||
attributes.ended = true; | ||
global.ended = true; | ||
} | ||
var events = attributes.events; | ||
var events = global.events; | ||
events.emit.apply(events, arguments); | ||
@@ -362,3 +357,3 @@ return this; | ||
var async = this.attributes.async; | ||
var async = this.global.async; | ||
var isCompleted = false; | ||
@@ -365,0 +360,0 @@ |
@@ -27,3 +27,3 @@ { | ||
}, | ||
"version": "1.1.1" | ||
"version": "1.1.2" | ||
} |
28280
669