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:
@@ -17,6 +17,7 @@ process_mode = 3
|
|||||||
script = ExtResource("3_18f1s")
|
script = ExtResource("3_18f1s")
|
||||||
|
|
||||||
[node name="Placeholder" type="Sprite2D" parent="."]
|
[node name="Placeholder" type="Sprite2D" parent="."]
|
||||||
|
visible = false
|
||||||
position = Vector2(580.25, 314.25)
|
position = Vector2(580.25, 314.25)
|
||||||
scale = Vector2(0.532715, 0.532715)
|
scale = Vector2(0.532715, 0.532715)
|
||||||
texture = ExtResource("4_vknm6")
|
texture = ExtResource("4_vknm6")
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ func GetRemoteImage(url):
|
|||||||
|
|
||||||
timeout = 1000
|
timeout = 1000
|
||||||
request(url)
|
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 res = await request_completed
|
||||||
var magicBytes = res[3].slice(0,8)
|
var magicBytes = res[3].slice(0,8)
|
||||||
print(magicBytes)
|
print(magicBytes)
|
||||||
@@ -30,8 +33,10 @@ func GetRemoteImage(url):
|
|||||||
error = image.load_jpg_from_buffer(res[3])
|
error = image.load_jpg_from_buffer(res[3])
|
||||||
if error != OK:
|
if error != OK:
|
||||||
print("Error fetching image ", str(error))
|
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:
|
else:
|
||||||
image.save_png(outFile)
|
image.save_png(outFile)
|
||||||
print("Saved new image to cache. " + outFile)
|
print("Saved new image to cache. " + outFile)
|
||||||
|
|
||||||
return image
|
return image
|
||||||
|
|||||||
Reference in New Issue
Block a user