On 18/08/2022 23:13, Alex Tweedly via use-livecode wrote:
However, the lazy load example still contains bugs due to race conditions
Solution:
replace the card script with the following .... should fix all the race
conditions I can see.
local sURLToIndex
on onlineImage pIndex, pURL
put pIndex &CR after sURLToIndex[pURL]
load URL pURL with message "downloadComplete"
end onlineImage
on downloadComplete pURL, pSatus
local tURL
repeat for each line L in sURLToIndex[pURL]
set the itemPointer of widget "PolyList" to L
set the subItemPointer of widget "PolyList" to "url"
put the subitemContent of widget "PolyList" into tURL
if tURL = pURL then -- still the right URL
set the subItemPointer of widget "PolyList" to "image"
set the subitemContent of widget "PolyList" to URL pURL
end if
end repeat
put empty into sURLToIndex[pURL]
end downloadComplete
And in the real world, add in cache aging, limit on number of entries,
limit on total cache size in bytes, ...
Alex.
1. if multiple entries reference the same image, then there is a
chance the earlier ones never get properly updated (sURLToIndex[pURL]
will have been overwritten by the next call to onlineImage before the
image value gets set).
2. if the user (or anything else) resets the dataContent of the widget
while there are outstanding "load URL"s, then when the
downloadComplete is triggered, it will set the image value for some
random new item to the image of the earlier one.
3. And if the one which was wrongly set in case 2 above also happens
to be a URL that occurs multiple time (i.e. case 1 above), then that
wrongly set image will remain "forever".
_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode