Both defer and withDelay now properly pass the envelope along with the data for the callback. Fixes #41

This commit is contained in:
Doug Neiner 2013-09-04 14:44:25 -05:00
parent d964b85cae
commit 6680cb497d
4 changed files with 15 additions and 13 deletions

View file

@ -112,9 +112,9 @@
defer : function () {
var fn = this.callback;
this.callback = function ( data ) {
this.callback = function ( data, env ) {
setTimeout( function () {
fn( data );
fn( data, env );
}, 0 );
};
return this;
@ -188,9 +188,9 @@
throw "Milliseconds must be a number";
}
var fn = this.callback;
this.callback = function ( data ) {
this.callback = function ( data, env ) {
setTimeout( function () {
fn( data );
fn( data, env );
}, milliseconds );
};
return this;

2
lib/postal.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -107,14 +107,15 @@ describe( "SubscriptionDefinition", function () {
var results = [], sDefe;
it( "Should defer the callback", function ( done ) {
sDefe = new SubscriptionDefinition( "TestChannel", "TestTopic", function ( data ) {
sDefe = new SubscriptionDefinition( "TestChannel", "TestTopic", function ( data, env ) {
results.push( data );
expect( results[0] ).to.be( "first" );
expect( results[1] ).to.be( "second" );
expect( env.topic ).to.be( "TestTopic" );
done();
} ).defer();
sDefe.callback( "second" );
sDefe.callback( "second", { topic: "TestTopic" } );
results.push( "first" );
} );
} );
@ -123,13 +124,14 @@ describe( "SubscriptionDefinition", function () {
var results = [], sDefe;
it( "Should delay the callback", function ( done ) {
sDefe = new SubscriptionDefinition( "TestChannel", "TestTopic", function ( data ) {
sDefe = new SubscriptionDefinition( "TestChannel", "TestTopic", function ( data, env ) {
results.push( data );
expect( results[0] ).to.be( "first" );
expect( results[1] ).to.be( "second" );
expect( env.topic ).to.be( "TestTopic" );
done();
} ).withDelay( 200 );
sDefe.callback( "second" );
sDefe.callback( "second", { topic: "TestTopic" } );
results.push( "first" );
} );
} );

View file

@ -35,9 +35,9 @@ SubscriptionDefinition.prototype = {
defer : function () {
var fn = this.callback;
this.callback = function ( data ) {
this.callback = function ( data, env ) {
setTimeout( function () {
fn( data );
fn( data, env );
}, 0 );
};
return this;
@ -111,9 +111,9 @@ SubscriptionDefinition.prototype = {
throw "Milliseconds must be a number";
}
var fn = this.callback;
this.callback = function ( data ) {
this.callback = function ( data, env ) {
setTimeout( function () {
fn( data );
fn( data, env );
}, milliseconds );
};
return this;