Preload songs only after the song list has loaded
At startup and after resetting the playlist, loading the song list and preloading the first song started at the same time. When the list answered last, it cleared the playlist and dropped the preloaded song. Preloading now starts once the list has loaded, and loading the list is retried if it fails.
This commit is contained in:
1 parent
ed292877ef
commit
739d0f7af6
5 files changed
+78
-8
No files matched your search
@@ -13,6 +13,7 @@ var requested_methods: Array[int] = []
|
||||
|
||||
var _responses: Dictionary = {}
|
||||
var _successes_left: Dictionary = {}
|
||||
var _held_paths: Dictionary = {}
|
||||
var _previous_transport: HttpTransport
|
||||
|
||||
|
||||
@@ -49,6 +50,20 @@ func fail_after(path: String, successes: int) -> void:
|
||||
_successes_left[path] = successes
|
||||
|
||||
|
||||
## Holds back responses to [param path] until [method release] is called, like a slow
|
||||
## server.
|
||||
func hold(path: String) -> void:
|
||||
_held_paths[path] = []
|
||||
|
||||
|
||||
## Delivers the responses held back for [param path] and stops holding it.
|
||||
func release(path: String) -> void:
|
||||
var waiting: Array = _held_paths.get(path, [])
|
||||
_held_paths.erase(path)
|
||||
for pending: Callable in waiting:
|
||||
pending.call()
|
||||
|
||||
|
||||
## Returns how many times [param path] has been requested.
|
||||
func count(path: String) -> int:
|
||||
return requested_paths.count(path)
|
||||
@@ -58,6 +73,13 @@ func request(url: String, method: int, on_complete: Callable) -> void:
|
||||
var path: String = url.trim_prefix(Settings.default_path)
|
||||
requested_paths.append(path)
|
||||
requested_methods.append(method)
|
||||
if _held_paths.has(path):
|
||||
_held_paths[path].append(_answer.bind(path, on_complete))
|
||||
return
|
||||
_answer(path, on_complete)
|
||||
|
||||
|
||||
func _answer(path: String, on_complete: Callable) -> void:
|
||||
if _successes_left.has(path):
|
||||
if _successes_left[path] == 0:
|
||||
on_complete.call(503, PackedByteArray())
|
||||
|
||||
Reference in new issue
Block a user