Skip to content

Commit

Permalink
don't skip the other q's when no callback exists
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudshift committed Feb 14, 2012
1 parent e9d7f48 commit da753f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
3 changes: 0 additions & 3 deletions cloudshift/flow/InternalApi.hx
Expand Up @@ -4,12 +4,9 @@ package cloudshift.flow;
import cloudshift.Core;
import cloudshift.Flow;


interface MessageQ {
function append(pkt:Dynamic):Void;
function setFlusher(cb:MessageQ->Bool):Void;
function startFlushing(sessID:String):Void;
function stopFlushing():Void;
function sessID():String;
function deQueue():Array<Dynamic>;
}
Expand Down
35 changes: 12 additions & 23 deletions cloudshift/flow/MessageQImpl.hx
Expand Up @@ -9,6 +9,7 @@ class MessageQImpl implements MessageQ {

static var timer:Int = -1;
static var waitingQs:Array<MessageQ> = [];
static var deferredQs:Array<MessageQ> = [];
static var flusher:MessageQ->Bool;

var _mq:Array<Dynamic>;
Expand All @@ -25,18 +26,20 @@ class MessageQImpl implements MessageQ {
static function initFlush() {
if (timer == -1) {
timer = js.Node.setInterval(function() {
try {
while (waitingQs.length > 0) {
var mq:MessageQ = waitingQs.shift();
if (!flusher(mq) ) {
waitingQs.push(mq);
break;
}
while (waitingQs.length > 0) {
var mq:MessageQ = waitingQs.shift();
if (!flusher(mq) ) {
deferredQs.push(mq);
}
} catch(exc:Dynamic) {
Core.info("Got exc:"+exc);
}
},200,null);


var deferredTimer = js.Node.setInterval(function() {
if (deferredQs.length > 1)
waitingQs.push(deferredQs.shift());
},200,null);

}
}

Expand Down Expand Up @@ -65,18 +68,4 @@ class MessageQImpl implements MessageQ {

public inline function sessID() { return _sessID; }

public function
startFlushing(sessID:String) {
/*
if (flusher != null) {
timer = js.Node.setInterval(function() {
},250,null);
}
*/
}

public function
stopFlushing() {
//js.Node.clearInterval(timer);
}
}
2 changes: 0 additions & 2 deletions cloudshift/flow/PushSessionImpl.hx
Expand Up @@ -34,12 +34,10 @@ class PushSessionImpl implements ConduitSession {
public function
flusher(flush:MessageQ->Bool) {
mq.setFlusher(flush);
mq.startFlushing(sessID);
}

public function
shutDown() {
mq.stopFlushing();
mq = null;
trace("removed all subs for "+sessID);
subs.values().foreach(function(f) f());
Expand Down

0 comments on commit da753f1

Please sign in to comment.