uliwitness / Stacksmith

An intuitive software erector kit targeted at people new to programming, but with enough potential to stay useful once they've learned, inspired by HyperCard.
http://stacksmith.org
131 stars 13 forks source link

Rewrite download command to be "synchronous". #96

Open uliwitness opened 5 years ago

uliwitness commented 5 years ago

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.

uliwitness commented 5 years ago

Note: #89 should be done before this, or can likely be done as part of this.

uliwitness commented 5 years ago

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?

uliwitness commented 4 years ago

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.