Reputation: 269
is it possible to execute publish function before history function.
PUBNUB_demo.publish({
channel: 'demo_tutorial',
message: {"color":"blue"}
});
PUBNUB_demo.history({
channel : 'demo_tutorial',
count : 100,
callback : function(m){console.log(m)}
});
for some reason history function executes before publish function is it possible to change that so publish function is executes always first
Upvotes: 2
Views: 76
Reputation: 4738
JavaScript is asynchronous so history is called before publish function completes. To do this properly, you need to call history inside of the publish success callback like this:
PUBNUB_demo.publish({
channel: 'demo_tutorial',
message: {"color":"blue"},
success: function(){
PUBNUB_demo.history({
channel : 'demo_tutorial',
count : 100,
callback : function(m){console.log(m)}
});
}
});
Upvotes: 3