Assigning and retrieving property values

Here’s my situation. I have a GET request to a network socket that retrieves info from an API. In the PageReceived event handler I parse several of the data items received. Depending on the value of one of the item, a call is made to a method that will, itself make another GET request to a different API (using a different socket). In the PageReceived handler of the second socket, a property (global to the main window) gets set. When code flow returns to complete the first socket’s PageReceived handler it needs to retrieve the value set by the second handler but seems to return NIL. Here’s an (attempt) at the code flow:

Call Socket 1 PageReceived processing...processing Call Socket 2 PageReceived processing...set window's property with valid value End PageReceived Socket 2 processing..,processing retrieve window's property < --- here the resulting assignment to the local variable returns nil End PageReceived Socket 1

If I set a breakpoint immediately after the retrieve window’s property statement, the debugger shows the assigned variable has nothing but if I look at the window’s property it shows the correct value. So my thinking is that the property isn’t really assigned for use until the PageReceived event for socket 1 actually terminated, even though the property was set in a different, nested handler.

Now here are a few things I’ve tried. First, it doesn’t matter if I’m using a Xojo.Core.HTTPSocket or a URLConnection socket. Next, I tried to stick the Socket 2 in a separate thread; same results. The second socket’s PageReceived handler has exactly six lines of code: 2 to check if the call succeeded and return a message if it failed, 1 to convert to a JSONItem, 2 to parse the content received, and 1 to set the window’s property.

The only thing I’ve done that got it to work was having the call to Socket 2 be a synchronous mode call. Since I’d rather not use a synchronous mode, if possible, I’m hoping someone might have an idea for me before I decide to just rip it apart and restructure the whole thing.

The First socket needs to complete before you can call the second.

You can call the second socket via call later even with a timeout of zero it will let the first socket finish before calling the second

xojo.core.Timer.CallLater(0, addressof SetProcessingOptions)