@@ -240,6 +240,7 @@ class Comms:
240240 sendSwitching_ outbox_ .receive --now = true
241241 yield // on each message sent
242242
243+
243244 // Send a message, and possibly do advanced things before after and during sending
244245 send msg / protocol.Message
245246 --now / bool = false // Should it be send now, of via the outbox
@@ -297,6 +298,46 @@ class Comms:
297298 return latch
298299 return null
299300
301+ send-new msg / protocol.Message
302+ --flush / bool = false
303+ --timeout / Duration = ( Duration --s = 60 ) -> protocol.Message? :
304+ // Ensure the message has a known message id
305+ if not ( msg .header .data .has-data protocol .Header .TYPE-MESSAGE-ID ) :
306+ msg .header .data .add-data-uint32 protocol .Header .TYPE-MESSAGE-ID msgIdGenerator .next
307+
308+ logger_ .with-level log .DEBUG-LEVEL :
309+ logger_ .debug "SEND: $( msg ) "
310+
311+ latch := monitor .Latch
312+ latchForMessage [ msg .msgId ] = latch
313+ waitTimeouts [ msg .msgId ] = Time .now + timeout
314+
315+ sendSwitching_ msg --now = flush
316+
317+ return latch .get
318+
319+ send-new msg / protocol.Message --async
320+ --callback / Lambda? = null
321+ --flush / bool = false
322+ --timeout / Duration = ( Duration --s = 60 ) -> monitor.Latch? :
323+ // Ensure the message has a known message id
324+ if not ( msg .header .data .has-data protocol .Header .TYPE-MESSAGE-ID ) :
325+ msg .header .data .add-data-uint32 protocol .Header .TYPE-MESSAGE-ID msgIdGenerator .next
326+
327+ logger_ .with-level log .DEBUG-LEVEL :
328+ logger_ .debug "SEND: $( msg ) "
329+
330+ latch := monitor .Latch
331+ latchForMessage [ msg .msgId ] = latch
332+ waitTimeouts [ msg .msgId ] = Time .now + timeout
333+
334+ sendSwitching_ msg --now = flush
335+
336+ if callback :
337+ task ::
338+ callback .call latch .get
339+ return latch
340+
300341 // Send directly, or via the outbox
301342 sendSwitching_ msg / protocol.Message --now / bool?= false :
302343 // TODO don't call this on both the outbox and regular paths, as it is messy
@@ -358,7 +399,7 @@ class Comms:
358399
359400 // Remove the timeout key, complete the latch, and remove all callbacks
360401 waitTimeouts .remove key
361- latchForMessage [ key ] .set false // false currently means timeout?
402+ latchForMessage [ key ] .set null // null, indicating there was no message received before the timeout
362403 latchForMessage .remove key
363404 lambdasForBadAck .remove key
364405 lambdasForGoodAck .remove key
0 commit comments