message_bus 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of message_bus might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0b70bc076d2e41296fabb4f0688efaf122fb75c
4
- data.tar.gz: 9e9416fc3384e18b3462de075c82e7e1c6b761b9
3
+ metadata.gz: 740688dfebf685690c2df41d642b6d0d642a537f
4
+ data.tar.gz: e33e81a4348f43cd7c5bff4005ee0741a66b0e05
5
5
  SHA512:
6
- metadata.gz: 5f859667b95a382bcfd9a759042f209c6d2d4eaa5803eead42a782e8742aca723e0cd58f234304dc507317c549586b18a857d883d60c824799baa4232bdd7d5a
7
- data.tar.gz: 65c3caf35cb1e41d8ed6565984171df215b4c96d85df5ba12e7ebfdb5244ac930e110ac1f92f9778a51a2e692871271606c7add272b5aca29a4c464b79a5eb78
6
+ metadata.gz: 29e24274cc3c2be1bcdf8b937151bdb5e74797135895c2932353a2949ed9e5a73ee42d8605e0d1a48863e012efffdbaf4810e036c723f72e2bd6faea8c08a2bb
7
+ data.tar.gz: b199a7e3a01811b295d973aa6b8611bd614bda39242424675a5903461535e3f4f27da1cf7a676caaafe2fafb0c310116dfd16f67e324f2f67f191cd23e4f4b98
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 16-03-2015
2
+ - Version 1.0.7
3
+ - Feature: added pause and resume methods
4
+
1
5
  03-02-2015
2
6
  - Version 1.0.6
3
7
  - Fix: global backlog not truncating correctly
@@ -10,7 +10,7 @@
10
10
  window.MessageBus = (function() {
11
11
  // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
12
12
  var callbacks, clientId, failCount, shouldLongPoll, queue, responseCallbacks, uniqueId, baseUrl;
13
- var me, started, stopped, longPoller, pollTimeout;
13
+ var me, started, stopped, longPoller, pollTimeout, paused, later;
14
14
 
15
15
  uniqueId = function() {
16
16
  return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
@@ -28,6 +28,8 @@ window.MessageBus = (function() {
28
28
  interval = null;
29
29
  failCount = 0;
30
30
  baseUrl = "/";
31
+ paused = false;
32
+ later = [];
31
33
 
32
34
  var hiddenProperty;
33
35
 
@@ -54,6 +56,35 @@ window.MessageBus = (function() {
54
56
  var totalAjaxCalls = 0;
55
57
  var lastAjax;
56
58
 
59
+ var processMessages = function(messages) {
60
+ var gotDate = false;
61
+ if (!messages) return false; // server unexpectedly closed connection
62
+
63
+ $.each(messages,function(_,message) {
64
+ gotData = true;
65
+ $.each(callbacks, function(_,callback) {
66
+ if (callback.channel === message.channel) {
67
+ callback.last_id = message.message_id;
68
+ try {
69
+ callback.func(message.data);
70
+ }
71
+ catch(e){
72
+ if(console.log) {
73
+ console.log("MESSAGE BUS FAIL: callback " + callback.channel + " caused exception " + e.message);
74
+ }
75
+ }
76
+ }
77
+ if (message.channel === "/__status") {
78
+ if (message.data[callback.channel] !== undefined) {
79
+ callback.last_id = message.data[callback.channel];
80
+ }
81
+ }
82
+ });
83
+ });
84
+
85
+ return gotData;
86
+ };
87
+
57
88
  longPoller = function(poll,data){
58
89
  var gotData = false;
59
90
  var aborted = false;
@@ -71,28 +102,15 @@ window.MessageBus = (function() {
71
102
  },
72
103
  success: function(messages) {
73
104
  failCount = 0;
74
- if (messages === null) return; // server unexpectedly closed connection
75
- $.each(messages,function(_,message) {
76
- gotData = true;
77
- $.each(callbacks, function(_,callback) {
78
- if (callback.channel === message.channel) {
79
- callback.last_id = message.message_id;
80
- try {
81
- callback.func(message.data);
82
- }
83
- catch(e){
84
- if(console.log) {
85
- console.log("MESSAGE BUS FAIL: callback " + callback.channel + " caused exception " + e.message);
86
- }
87
- }
88
- }
89
- if (message.channel === "/__status") {
90
- if (message.data[callback.channel] !== undefined) {
91
- callback.last_id = message.data[callback.channel];
92
- }
93
- }
94
- });
95
- });
105
+ if (paused) {
106
+ if (messages) {
107
+ $.each(messages, function(_,message) {
108
+ later.push(messages);
109
+ });
110
+ }
111
+ } else {
112
+ gotData = processMessages(messages);
113
+ }
96
114
  },
97
115
  error: function(xhr, textStatus, err) {
98
116
  if(textStatus === "abort") {
@@ -157,6 +175,16 @@ window.MessageBus = (function() {
157
175
  console.log("Last ajax call: " + (new Date() - lastAjax) / 1000 + " seconds ago") ;
158
176
  },
159
177
 
178
+ pause: function() {
179
+ paused = true;
180
+ },
181
+
182
+ resume: function() {
183
+ paused = false;
184
+ processMessages(later);
185
+ later = [];
186
+ },
187
+
160
188
  stop: function() {
161
189
  stopped = true;
162
190
  started = false;
@@ -1,3 +1,3 @@
1
1
  module MessageBus
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -10,7 +10,7 @@
10
10
  window.MessageBus = (function() {
11
11
  // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
12
12
  var callbacks, clientId, failCount, shouldLongPoll, queue, responseCallbacks, uniqueId, baseUrl;
13
- var me, started, stopped, longPoller, pollTimeout;
13
+ var me, started, stopped, longPoller, pollTimeout, paused, later;
14
14
 
15
15
  uniqueId = function() {
16
16
  return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
@@ -28,6 +28,8 @@ window.MessageBus = (function() {
28
28
  interval = null;
29
29
  failCount = 0;
30
30
  baseUrl = "/";
31
+ paused = false;
32
+ later = [];
31
33
 
32
34
  var hiddenProperty;
33
35
 
@@ -54,6 +56,35 @@ window.MessageBus = (function() {
54
56
  var totalAjaxCalls = 0;
55
57
  var lastAjax;
56
58
 
59
+ var processMessages = function(messages) {
60
+ var gotDate = false;
61
+ if (!messages) return false; // server unexpectedly closed connection
62
+
63
+ $.each(messages,function(_,message) {
64
+ gotData = true;
65
+ $.each(callbacks, function(_,callback) {
66
+ if (callback.channel === message.channel) {
67
+ callback.last_id = message.message_id;
68
+ try {
69
+ callback.func(message.data);
70
+ }
71
+ catch(e){
72
+ if(console.log) {
73
+ console.log("MESSAGE BUS FAIL: callback " + callback.channel + " caused exception " + e.message);
74
+ }
75
+ }
76
+ }
77
+ if (message.channel === "/__status") {
78
+ if (message.data[callback.channel] !== undefined) {
79
+ callback.last_id = message.data[callback.channel];
80
+ }
81
+ }
82
+ });
83
+ });
84
+
85
+ return gotData;
86
+ };
87
+
57
88
  longPoller = function(poll,data){
58
89
  var gotData = false;
59
90
  var aborted = false;
@@ -71,28 +102,15 @@ window.MessageBus = (function() {
71
102
  },
72
103
  success: function(messages) {
73
104
  failCount = 0;
74
- if (messages === null) return; // server unexpectedly closed connection
75
- $.each(messages,function(_,message) {
76
- gotData = true;
77
- $.each(callbacks, function(_,callback) {
78
- if (callback.channel === message.channel) {
79
- callback.last_id = message.message_id;
80
- try {
81
- callback.func(message.data);
82
- }
83
- catch(e){
84
- if(console.log) {
85
- console.log("MESSAGE BUS FAIL: callback " + callback.channel + " caused exception " + e.message);
86
- }
87
- }
88
- }
89
- if (message.channel === "/__status") {
90
- if (message.data[callback.channel] !== undefined) {
91
- callback.last_id = message.data[callback.channel];
92
- }
93
- }
94
- });
95
- });
105
+ if (paused) {
106
+ if (messages) {
107
+ $.each(messages, function(_,message) {
108
+ later.push(messages);
109
+ });
110
+ }
111
+ } else {
112
+ gotData = processMessages(messages);
113
+ }
96
114
  },
97
115
  error: function(xhr, textStatus, err) {
98
116
  if(textStatus === "abort") {
@@ -157,6 +175,16 @@ window.MessageBus = (function() {
157
175
  console.log("Last ajax call: " + (new Date() - lastAjax) / 1000 + " seconds ago") ;
158
176
  },
159
177
 
178
+ pause: function() {
179
+ paused = true;
180
+ },
181
+
182
+ resume: function() {
183
+ paused = false;
184
+ processMessages(later);
185
+ later = [];
186
+ },
187
+
160
188
  stop: function() {
161
189
  stopped = true;
162
190
  started = false;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack