SOAP - Problem with separate threads

Andre Garzia andre at andregarzia.com
Wed Oct 24 11:15:40 EDT 2007


Hello Dave,

you can't use wait. Even wait with messages. If you use waits and for
some reason you have nested wait blocks, you need to unblock them from
the inner to the outer or they will still be blocked. With the nature
of your software where you have two streams causing the waits - the
server pool and the actions that cause SOAP requests - this nested
blocks could get really ugly. I try never to use wait in my software.

You mail before this one, you pondered about how to return data to the
function that called the SOAP request. What I'd do is like this, one
of the parameters for the SOAP request function would be a callback.
Like libURL does.

function LibSoapSendRPCRequest
theSoapID,theSoapAction,theMethod,theHeader,theParams,theCallBack

With that you must store in your queue both the callback message and
the target that called the message. When your request is done, you
send the result to the callback message. A simple silly implementation
is below:

local lQueue

on addToQueue pURL, pCallback
  put pURL & "|" & pCallback & "|" the long id of the target & cr after lQueue
end addToQueue

on DownloadNextFile
   set the itemdel to "|"
   get item 1 of line 1 of lQueue
   load URL it with message "downloadComplete"
end DownloadNextFile

on DownloadComplete pURL, pData
    set the itemdel to "|"
    put format("send %s \"%s\", \"%s\" to %s", item 2 of line 1 of
lQueue, pURL, pDATA, item 3 of line 1 of lQueue) into tCmd
    do tCmd
    delete line 1 of lQueue
    DownloadNextFile
end DownloadComplete

This above is a simple file download queue where each file is
acknowledge by sending a callback message back to the object that
called the addToQueue function. You could use it like this:

addToQueue "http://server/file1", "file1_complete"
addToQueue "http://server/file1", "file2_complete"

And have callbacks on the same object such as these below in the same
object that called the addtoqueue handler.

on file1_complete pURL, pData
  -- do stuff for file 1.
end file1_complete

on file2_complete pURL, pData
  -- do stuff for file 2.
end file2_complete

I hope you get the idea. Check the docs for more information for the
following commands: send, the target, long id, urlstatus. By combining
this, you can create your own queues. Of course there are others ways
of doing it but this is a quick one.

Cheers
andre



More information about the use-livecode mailing list