NAME

mbx_when_reply - Asynchronous Send and Reply Message Interaction

SYNOPSIS

package require dmh
::dmh::mbx_when_reply boxname message reply_code ?timeout_code? ?timeout?

DESCRIPTION

This procedure is used to send a DMH message to a mailbox, and to register code to execute when the reply message is received, or a timeout has occurred.  The procedure has the benefit of letting you conveniently code send-and-reply interactions using asynchronous mechanisms that do not force your application into modal, nested event loops that may cause unresponsiveness or interfere with handling events in the order received.

The procedure manages creating a unique reply mailbox for the reply message, and closes the mailbox after use.  The timeout interval for receiving a reply message is optionally specified in milliseconds; the default value is 20000 (20 seconds).  When a reply is received within the timeout interval, it is appended to the reply_code as a list element, and the result is executed at the topmost (global) level of the interpreter.  You may optionally specify timeout_code to be executed if the reply message is not received within the specified interval.  The default timeout behavior is to append the literal value TIMEOUT to the reply_code as a list element and execute the result, as if the TIMEOUT value was the data of a received message.  If you do specify a value for the timeout_code argument, your value is executed without the literal value TIMEOUT being appended to it.

The command is part of the dmh package and it exists in the ::dmh namespace.

EXAMPLE

package require dmh

proc refresh_lb_callback {listbox reply_message} {
   #puts "received reply: $reply_msg"
   if { [winfo exists $listbox] } {
      # update listbox to show reply data
      #...
      }
   }

# ...
# refresh listbox contents asynchronously
::dmh::mbx_when_reply DATAHUB [list eval dc_items_view] [list refresh_lb_callback $listbox]
# ...

AUTHOR

Hume Integration Software, www.hume.com

SEE ALSO

mbx    mbx_do_xact

KEYWORDS

mbx, DMH, IPC, interprocess communication, messaging