mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-03-16 22:20:23 +00:00
Both defer and withDelay now properly pass the envelope along with the data for the callback. Fixes #41
This commit is contained in:
parent
d964b85cae
commit
6680cb497d
4 changed files with 15 additions and 13 deletions
|
|
@ -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
2
lib/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -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" );
|
||||
} );
|
||||
} );
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue