I was trying to make an auto-update script for my packages. It would find, download and install the latest version. The problem is that sometimes URLSaveAsynchronous
hangs. This happens more often on Windows than on other platforms, but it doesn't always happen. The frustrating thing is that since it happens randomly, I can't easy test for the reason.
Does anyone have a clue about what may be wrong?
The piece of code that hangs:
progress = 0.;
ProgressIndicator[Dynamic[progress]];
URLSaveAsynchronous[
"https://github.com/szhorvat/MaTeX/releases/download/v1.6.2/MaTeX-1.6.2.paclet",
CreateFile[],
If[#2 === "progress", progress = Quiet[#3[[1]]/#3[[2]]] ] &,
"Progress" -> True
]
At this moment I am really not sure whether the hang is related to the progress indicator. I observed the problem on all OSs, but it happened most often on Windows with M11.0.
The same thing in context is below. Note that the code is intended to be compatible with M10.0. I know that there are newer functions for some of these things.
updateMaTeX[] :=
Module[{json, download, target, progress = 0.},
Check[
json = Import["https://api.github.com/repos/szhorvat/MaTeX/releases/latest", "JSON"];
download = Lookup[First@Lookup[json, "assets"], "browser_download_url"];
target = FileNameJoin[{CreateDirectory[], "MaTeX.paclet"}];
PrintTemporary@ProgressIndicator[Dynamic[progress]];
WaitAsynchronousTask@URLSaveAsynchronous[
download, target,
If[#2 === "progress", progress = Quiet[#3[[1]]/#3[[2]]] ] &,
"Progress" -> True
]
,
Return[$Failed]
];
If[FileExistsQ[target], PacletInstall[target], $Failed]
]