Skip to content

Commit dc55a23

Browse files
author
Devendra
committed
adding flag no_wait_for_pending default false
1 parent a088288 commit dc55a23

22 files changed

Lines changed: 266 additions & 183 deletions

File tree

core/pubnub-common.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ function PN_API(setup) {
207207
, SUB_BUFF_WAIT = 0
208208
, TIMETOKEN = 0
209209
, CHANNELS = {}
210+
, NO_WAIT_FOR_PENDING = setup['no_wait_for_pending']
210211
, xdr = setup['xdr']
211212
, error = setup['error'] || function() {}
212213
, _is_online = setup['_is_online'] || function() { return 1 }
@@ -215,9 +216,15 @@ function PN_API(setup) {
215216
, UUID = setup['uuid'] || ( db && db['get'](SUBSCRIBE_KEY+'uuid') || '');
216217

217218
function publish(next) {
218-
if (next) PUB_QUEUE.sending = 0;
219-
if (PUB_QUEUE.sending || !PUB_QUEUE.length) return;
220-
PUB_QUEUE.sending = 1;
219+
220+
if (NO_WAIT_FOR_PENDING) {
221+
if (!PUB_QUEUE.length) return;
222+
} else {
223+
if (next) PUB_QUEUE.sending = 0;
224+
if ( PUB_QUEUE.sending || !PUB_QUEUE.length ) return;
225+
PUB_QUEUE.sending = 1;
226+
}
227+
221228
xdr(PUB_QUEUE.shift());
222229
}
223230

modern/pubnub.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ function PN_API(setup) {
208208
, SUB_BUFF_WAIT = 0
209209
, TIMETOKEN = 0
210210
, CHANNELS = {}
211+
, NO_WAIT_FOR_PENDING = setup['no_wait_for_pending']
211212
, xdr = setup['xdr']
212213
, error = setup['error'] || function() {}
213214
, _is_online = setup['_is_online'] || function() { return 1 }
@@ -216,9 +217,15 @@ function PN_API(setup) {
216217
, UUID = setup['uuid'] || ( db && db['get'](SUBSCRIBE_KEY+'uuid') || '');
217218

218219
function publish(next) {
219-
if (next) PUB_QUEUE.sending = 0;
220-
if (PUB_QUEUE.sending || !PUB_QUEUE.length) return;
221-
PUB_QUEUE.sending = 1;
220+
221+
if (NO_WAIT_FOR_PENDING) {
222+
if (!PUB_QUEUE.length) return;
223+
} else {
224+
if (next) PUB_QUEUE.sending = 0;
225+
if ( PUB_QUEUE.sending || !PUB_QUEUE.length ) return;
226+
PUB_QUEUE.sending = 1;
227+
}
228+
222229
xdr(PUB_QUEUE.shift());
223230
}
224231

modern/pubnub.min.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node.js/examples/hello.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
http://www.pubnub.com/account#api-keys
55
66
--------------------------------------------------------------------------- */
7-
console.log('Type your message, press ENTER.\n');
87

98
var pubnub = require("./../pubnub.js").init({
109
publish_key : "demo",
@@ -15,20 +14,9 @@ var pubnub = require("./../pubnub.js").init({
1514
Listen for Messages
1615
--------------------------------------------------------------------------- */
1716
pubnub.subscribe({
18-
channel : "my_channel",
17+
channel : "a",
18+
windowing : 10000,
1919
callback : function(message) {
2020
console.log( " > ", message );
2121
}
2222
});
23-
24-
/* ---------------------------------------------------------------------------
25-
Type Console Message
26-
--------------------------------------------------------------------------- */
27-
var stdin = process.openStdin();
28-
stdin.on( 'data', function(chunk) {
29-
pubnub.publish({
30-
channel : "my_channel",
31-
message : ''+chunk
32-
});
33-
});
34-

node.js/pubnub.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ function PN_API(setup) {
208208
, SUB_BUFF_WAIT = 0
209209
, TIMETOKEN = 0
210210
, CHANNELS = {}
211+
, NO_WAIT_FOR_PENDING = setup['no_wait_for_pending']
211212
, xdr = setup['xdr']
212213
, error = setup['error'] || function() {}
213214
, _is_online = setup['_is_online'] || function() { return 1 }
@@ -216,9 +217,15 @@ function PN_API(setup) {
216217
, UUID = setup['uuid'] || ( db && db['get'](SUBSCRIBE_KEY+'uuid') || '');
217218

218219
function publish(next) {
219-
if (next) PUB_QUEUE.sending = 0;
220-
if (PUB_QUEUE.sending || !PUB_QUEUE.length) return;
221-
PUB_QUEUE.sending = 1;
220+
221+
if (NO_WAIT_FOR_PENDING) {
222+
if (!PUB_QUEUE.length) return;
223+
} else {
224+
if (next) PUB_QUEUE.sending = 0;
225+
if ( PUB_QUEUE.sending || !PUB_QUEUE.length ) return;
226+
PUB_QUEUE.sending = 1;
227+
}
228+
222229
xdr(PUB_QUEUE.shift());
223230
}
224231

@@ -1056,6 +1063,8 @@ function xdr( setup ) {
10561063
path : url,
10571064
method : 'GET'
10581065
};
1066+
options.agent = false;
1067+
require('http').globalAgent.maxSockets = Infinity;
10591068
try {
10601069
request = (ssl ? https : http).request(options, function(response) {
10611070
response.setEncoding('utf8');

node.js/unassembled/platform.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ function xdr( setup ) {
113113
path : url,
114114
method : 'GET'
115115
};
116+
options.agent = false;
117+
require('http').globalAgent.maxSockets = Infinity;
116118
try {
117119
request = (ssl ? https : http).request(options, function(response) {
118120
response.setEncoding('utf8');

phonegap/pubnub.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ function PN_API(setup) {
208208
, SUB_BUFF_WAIT = 0
209209
, TIMETOKEN = 0
210210
, CHANNELS = {}
211+
, NO_WAIT_FOR_PENDING = setup['no_wait_for_pending']
211212
, xdr = setup['xdr']
212213
, error = setup['error'] || function() {}
213214
, _is_online = setup['_is_online'] || function() { return 1 }
@@ -216,9 +217,15 @@ function PN_API(setup) {
216217
, UUID = setup['uuid'] || ( db && db['get'](SUBSCRIBE_KEY+'uuid') || '');
217218

218219
function publish(next) {
219-
if (next) PUB_QUEUE.sending = 0;
220-
if (PUB_QUEUE.sending || !PUB_QUEUE.length) return;
221-
PUB_QUEUE.sending = 1;
220+
221+
if (NO_WAIT_FOR_PENDING) {
222+
if (!PUB_QUEUE.length) return;
223+
} else {
224+
if (next) PUB_QUEUE.sending = 0;
225+
if ( PUB_QUEUE.sending || !PUB_QUEUE.length ) return;
226+
PUB_QUEUE.sending = 1;
227+
}
228+
222229
xdr(PUB_QUEUE.shift());
223230
}
224231

0 commit comments

Comments
 (0)