Stacksmith
Stacksmith copied to clipboard
Rewrite download command to be "synchronous".
Like the "go" command pauses script execution to wait for a download and then resumes it afterwards, make the download
command work the same way, and maybe even change it into a url "foo:///bar/baz"
function.
The command's instruction would start the download, call LEOPauseContext()
, and from the download completion block call LEOResumeContext()
. When it is then called again, it would see that from the kLEOContextResuming
flag and instead of starting another download would return the file contents and/or set the result
to any error information.
Note: #89 should be done before this, or can likely be done as part of this.
Open questions: What do we do with headers, progress reporting etc.? Do we keep the download
command for that? Do we save the headers & status codes in a local variable the downloads
that can be accessed after the url
function finishes? Do we call a downloadProgress
handler so another part of the script can at least display progress?
Progress reporting could probably done by calling an optional closure, syntax maybe:
put url "http://example.com" for progress take percentage then put "Downloading:" && percentage
if status of the download is not 200 then
answer "Error downloading: " && the statusMessage of the download
end if
That way we don't duplicate stuff and can get rid of the download
command.