mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
Adjust HTTPClient example code to not break in HTML5 exports (#4738)
Fixes godotengine/godot#46857 Added supported wait periods after poll() for HTML5 This prevents warning about multiple polls in the same frame and prevent hanging the game when fetching the body chunks
This commit is contained in:
committed by
Hugo Locurcio
parent
c4a56adc06
commit
2875c009fa
@@ -34,7 +34,10 @@ It will connect and fetch a website.
|
||||
while http.get_status() == HTTPClient.STATUS_CONNECTING or http.get_status() == HTTPClient.STATUS_RESOLVING:
|
||||
http.poll()
|
||||
print("Connecting...")
|
||||
OS.delay_msec(500)
|
||||
if not OS.has_feature("web"):
|
||||
OS.delay_msec(500)
|
||||
else:
|
||||
yield(Engine.get_main_loop(), "idle_frame")
|
||||
|
||||
assert(http.get_status() == HTTPClient.STATUS_CONNECTED) # Could not connect
|
||||
|
||||
@@ -86,13 +89,16 @@ It will connect and fetch a website.
|
||||
while http.get_status() == HTTPClient.STATUS_BODY:
|
||||
# While there is body left to be read
|
||||
http.poll()
|
||||
var chunk = http.read_response_body_chunk() # Get a chunk.
|
||||
# Get a chunk.
|
||||
var chunk = http.read_response_body_chunk()
|
||||
if chunk.size() == 0:
|
||||
# Got nothing, wait for buffers to fill a bit.
|
||||
OS.delay_usec(1000)
|
||||
if not OS.has_feature("web"):
|
||||
# Got nothing, wait for buffers to fill a bit.
|
||||
OS.delay_usec(1000)
|
||||
else:
|
||||
yield(Engine.get_main_loop(), "idle_frame")
|
||||
else:
|
||||
rb = rb + chunk # Append to read buffer.
|
||||
|
||||
# Done!
|
||||
|
||||
print("bytes got: ", rb.size())
|
||||
|
||||
Reference in New Issue
Block a user