Scripts that are already running

Richard Gaskin ambassador at fourthworld.com
Fri Sep 24 15:38:11 EDT 2010


Jeff Massung wrote:

> That said, there are areas where LiveCode could - itself - benefit from
> multi-threading that isn't exposed to the end user. One example of this is
> in access to the internet, file, or various OS accesses. Being able to issue
> a large disk read/write and get a callback when done, and either a revamp or
> serious bug fix/cleaning of libURL. Or being able to wait on a particular
> event to be completed/happen. These alone would help considerably.

One small step in that direction, from the LiveCode 4.5 Release 
Notes.pdf (which is unfortunately buried deep inside the app bundle on 
OS X virtually guaranteeing no Mac customer will ever see it):


   Engine changes

   Non-blocking DNS resolution

   The open socket command no longer blocks on DNS resolution.
   Instead, if resolution is required the command will return
   immediately and the DNS lookup will happen in the background.
   If resolution fails, then a socketError message is sent in
   the same was as if connection fails.

   For applications using hostNameToAddress directly, its syntax
   has been augmented:
   hostnameToAddress(hostname, [ callback ])
   If the callback parameter is specified then the call will
   return immediately and upon completion of the lookup, the
   callback will be invoked with the resolved address as a
   parameter.


Another nifty new thing including in that unfortunately hidden document is:

   Slave process improvements

   A number of issues with the open process command and the engine
   itself have, up until now, conspired to make it difficult (if
   not impossible!) to either run a slave process, or use the
   engine as slave on all platforms.

   These issues have been resolved in this version, thus making it
   straightforward to run another process and poll for input and
   output over stdin/stdout.

   The typical form for this is along the following lines:

   local sSlaveProcess
   command startSlave pProcess
      open process sSlaveProcess for text update
      send “monitorSlave” to me in 50 millisecs
   end startSlave

   command monitorSlave
     repeat forever
       # Loop until there are no more lines to read.
       read from process sSlaveProcess for 1 line in 0 millisecs
       if the result is empty then
         # The slave has sent us something, so process it and loop for
         # (potentially) more data. else if the result is “timeout” then
         # There is nothing waiting for us, so exit repeat
         exit repeat
       else if the result is “eof” then
         # The slave has terminated, so do any final processing and
         # finish monitoring.
         close process sSlaveProcess
         exit monitorSlave
       else
         # Some error has occurred!
         exit monitorSlave
      end if
     end repeat
     send “monitorSlave” to me in 50 millisecs
   end monitorSlave

--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  LiveCode Journal blog: http://LiveCodejournal.com/blog.irv




More information about the use-livecode mailing list