Poll while fetching remote sources to avoid timeout

If we don't respond to pings for too long, Jose considers us dead.
That becomes a problem when fetching large resources or from a slow remote
This commit is contained in:
2023-08-07 17:29:36 +02:00
parent 0e71f372c3
commit 36344fb2cb
2 changed files with 7 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ process_mode = 3
script = ExtResource("3_18f1s")
[node name="Placeholder" type="Sprite2D" parent="."]
visible = false
position = Vector2(580.25, 314.25)
scale = Vector2(0.532715, 0.532715)
texture = ExtResource("4_vknm6")

View File

@@ -17,6 +17,9 @@ func GetRemoteImage(url):
timeout = 1000
request(url)
while get_http_client_status() != HTTPClient.STATUS_CONNECTED:
await get_tree().create_timer(0.001).timeout
$"/root/Main/JobServer".socket.poll()
var res = await request_completed
var magicBytes = res[3].slice(0,8)
print(magicBytes)
@@ -30,8 +33,10 @@ func GetRemoteImage(url):
error = image.load_jpg_from_buffer(res[3])
if error != OK:
print("Error fetching image ", str(error))
image = load("res://assets/fallback_card.png")
var fallback = load("res://assets/fallback_card.png")
image = fallback.get_image()
else:
image.save_png(outFile)
print("Saved new image to cache. " + outFile)
return image