Added queued transmitter.
This is a normal transmitter than doesn't act synchronously and instead queues messages for future processing. Can be useful to implement thread safe receive/transmit logic where a sub thread is requiring property changes that can be sent to a queued transmitter that is then processed in the main thread.
This commit is contained in:
parent
fee5276ae6
commit
8b03cb4e60
1 changed files with 28 additions and 1 deletions
|
@ -196,6 +196,32 @@ var Transmitter =
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var QueuedTransmitter =
|
||||||
|
{
|
||||||
|
new: func(_ident){
|
||||||
|
var new_class = { parents:[QueuedTransmitter], base:emesary.Transmitter};
|
||||||
|
new_class = emesary.Transmitter.new(_ident);
|
||||||
|
new_class.baseNotifyAll = new_class.NotifyAll;
|
||||||
|
new_class.Q = [];
|
||||||
|
|
||||||
|
new_class.NotifyAll = func(message){
|
||||||
|
append(me.Q, message);
|
||||||
|
return emesary.Transmitter.ReceiptStatus_Pending;
|
||||||
|
};
|
||||||
|
|
||||||
|
new_class.Process = func {
|
||||||
|
foreach (var m ; me.Q)
|
||||||
|
me.baseNotifyAll(m);
|
||||||
|
me.Q = [];
|
||||||
|
return emesary.Transmitter.ReceiptStatus_PendingFinished;
|
||||||
|
};
|
||||||
|
new_class.size = func {
|
||||||
|
return size(me.Q);
|
||||||
|
}
|
||||||
|
return new_class;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Base class for Notifications. By convention a Notification has a type and a value.
|
# Base class for Notifications. By convention a Notification has a type and a value.
|
||||||
|
@ -270,6 +296,7 @@ var Recipient =
|
||||||
# use this transmitters, however other transmitters can be created and merely use the global transmitter to discover each other
|
# use this transmitters, however other transmitters can be created and merely use the global transmitter to discover each other
|
||||||
var GlobalTransmitter = Transmitter.new("GlobalTransmitter");
|
var GlobalTransmitter = Transmitter.new("GlobalTransmitter");
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# This is basically a base64 like encode except we just use alphanumerics which gives us a base62 encode.
|
# This is basically a base64 like encode except we just use alphanumerics which gives us a base62 encode.
|
||||||
|
@ -506,4 +533,4 @@ var TransferCoord =
|
||||||
#print ("i ",i, " --> ", (TransferNorm.decode(TransferNorm.encode(i,2), 2,0)).value);
|
#print ("i ",i, " --> ", (TransferNorm.decode(TransferNorm.encode(i,2), 2,0)).value);
|
||||||
#debug.dump(TransferNorm.decode(TransferNorm.encode(-1,2), 2,0));
|
#debug.dump(TransferNorm.decode(TransferNorm.encode(-1,2), 2,0));
|
||||||
#debug.dump(TransferNorm.decode(TransferNorm.encode(0,2), 2,0));
|
#debug.dump(TransferNorm.decode(TransferNorm.encode(0,2), 2,0));
|
||||||
#debug.dump(TransferNorm.decode(TransferNorm.encode(1,2), 2,0));
|
#debug.dump(TransferNorm.decode(TransferNorm.encode(1,2), 2,0));
|
Loading…
Add table
Reference in a new issue