Comparing version 0.10.3 to 0.10.4
@@ -218,23 +218,26 @@ /* | ||
then: function(fnFulfill, fnReject) { | ||
this.thenListeners.push(fnFulfill); | ||
if (this.success) { | ||
Promise.doResolve(this, this.value); | ||
then: function(onSuccess, onFail) { | ||
if (isFunction(onSuccess)) { | ||
// proactive add | ||
this.thenListeners.push(onSuccess); | ||
if (this.success) { | ||
Promise.doResolve(this, this.value); | ||
} | ||
} | ||
if (fnReject) { | ||
this.catch(fnReject); | ||
if (isFunction(onFail)) { | ||
// proactive add | ||
this.catchListeners.push(onFail); | ||
if (this.fail) { | ||
Promise.doReject(this, this.reason); | ||
} | ||
} | ||
return this; | ||
}, | ||
catch: function(fn) { | ||
this.catchListeners.push(fn); | ||
if (this.fail) { | ||
Promise.doReject(this, this.reason); | ||
} | ||
return this; | ||
catch: function(onFail) { | ||
this.then(null, onFail); | ||
} | ||
}; | ||
Promise.doResolve = function resolve(p, value) { | ||
Promise.doResolve = function doResolve(p, value) { | ||
p.thenListeners.forEach(function(listener) { | ||
@@ -244,8 +247,8 @@ listener(value); | ||
p.completed = true; | ||
p.success = true; | ||
p.value = value; | ||
p.completed = true; | ||
}; | ||
Promise.doReject = function reject(p, reason) { | ||
Promise.doReject = function doReject(p, reason) { | ||
@@ -260,5 +263,5 @@ if (p.catchListeners.length === 0) { | ||
p.completed = true; | ||
p.fail = true; | ||
p.reason = reason; | ||
p.completed = true; | ||
}; | ||
@@ -505,7 +508,7 @@ | ||
shift: function() { | ||
read: function() { | ||
return this.array.shift(); | ||
}, | ||
push: function(value) { | ||
write: function(value) { | ||
if (this.isFull()) { return false } | ||
@@ -525,2 +528,9 @@ this.array.push(value); | ||
function isBuffer(b) { | ||
return (b | ||
&& isFunction(b.read) | ||
&& isFunction(b.write) | ||
&& isFunction(b.isFull) | ||
&& isFunction(b.isEmpty)); | ||
} | ||
@@ -585,3 +595,3 @@ // Channel: a structure to transport messages | ||
// clean and return | ||
return this.buffer.shift(); | ||
return this.buffer.read(); | ||
} | ||
@@ -626,6 +636,6 @@ }, | ||
// store sent value in the buffer | ||
this.buffer.push(this.transform(data)); | ||
this.buffer.write(this.transform(data)); | ||
// if any waiting for the data, give it | ||
if (this.receiverPromises[0]) { | ||
scheduledResolve(this.receiverPromises.shift(), this.buffer.shift()); | ||
scheduledResolve(this.receiverPromises.shift(), this.buffer.read()); | ||
} | ||
@@ -655,3 +665,3 @@ } | ||
CRL.chan = function chan(size, transform) { | ||
if (size instanceof Buffer) { | ||
if (isBuffer(size)) { | ||
return new Channel(size, transform); | ||
@@ -658,0 +668,0 @@ } |
{ | ||
"author" : "Yosbel Marin", | ||
"name" : "cor-lang", | ||
"version" : "0.10.3", | ||
"version" : "0.10.4", | ||
"license" : "BSD", | ||
@@ -6,0 +6,0 @@ "description" : "The Language of the Web", |
@@ -187,23 +187,26 @@ (function(){ | ||
then: function(fnFulfill, fnReject) { | ||
this.thenListeners.push(fnFulfill); | ||
if (this.success) { | ||
Promise.doResolve(this, this.value); | ||
then: function(onSuccess, onFail) { | ||
if (isFunction(onSuccess)) { | ||
// proactive add | ||
this.thenListeners.push(onSuccess); | ||
if (this.success) { | ||
Promise.doResolve(this, this.value); | ||
} | ||
} | ||
if (fnReject) { | ||
this.catch(fnReject); | ||
if (isFunction(onFail)) { | ||
// proactive add | ||
this.catchListeners.push(onFail); | ||
if (this.fail) { | ||
Promise.doReject(this, this.reason); | ||
} | ||
} | ||
return this; | ||
}, | ||
catch: function(fn) { | ||
this.catchListeners.push(fn); | ||
if (this.fail) { | ||
Promise.doReject(this, this.reason); | ||
} | ||
return this; | ||
catch: function(onFail) { | ||
this.then(null, onFail); | ||
} | ||
}; | ||
Promise.doResolve = function resolve(p, value) { | ||
Promise.doResolve = function doResolve(p, value) { | ||
p.thenListeners.forEach(function(listener) { | ||
@@ -213,8 +216,8 @@ listener(value); | ||
p.completed = true; | ||
p.success = true; | ||
p.value = value; | ||
p.completed = true; | ||
}; | ||
Promise.doReject = function reject(p, reason) { | ||
Promise.doReject = function doReject(p, reason) { | ||
@@ -229,5 +232,5 @@ if (p.catchListeners.length === 0) { | ||
p.completed = true; | ||
p.fail = true; | ||
p.reason = reason; | ||
p.completed = true; | ||
}; | ||
@@ -474,7 +477,7 @@ | ||
shift: function() { | ||
read: function() { | ||
return this.array.shift(); | ||
}, | ||
push: function(value) { | ||
write: function(value) { | ||
if (this.isFull()) { return false } | ||
@@ -494,2 +497,9 @@ this.array.push(value); | ||
function isBuffer(b) { | ||
return (b | ||
&& isFunction(b.read) | ||
&& isFunction(b.write) | ||
&& isFunction(b.isFull) | ||
&& isFunction(b.isEmpty)); | ||
} | ||
@@ -554,3 +564,3 @@ // Channel: a structure to transport messages | ||
// clean and return | ||
return this.buffer.shift(); | ||
return this.buffer.read(); | ||
} | ||
@@ -595,6 +605,6 @@ }, | ||
// store sent value in the buffer | ||
this.buffer.push(this.transform(data)); | ||
this.buffer.write(this.transform(data)); | ||
// if any waiting for the data, give it | ||
if (this.receiverPromises[0]) { | ||
scheduledResolve(this.receiverPromises.shift(), this.buffer.shift()); | ||
scheduledResolve(this.receiverPromises.shift(), this.buffer.read()); | ||
} | ||
@@ -624,3 +634,3 @@ } | ||
CRL.chan = function chan(size, transform) { | ||
if (size instanceof Buffer) { | ||
if (isBuffer(size)) { | ||
return new Channel(size, transform); | ||
@@ -627,0 +637,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
885087
15219