mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-07 02:12:07 +03:00
Merge pull request #8707 from trflorian/http-client-await
Replace yield with await in gd script for http client tutorial
This commit is contained in:
@@ -51,10 +51,7 @@ 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...")
|
||||
if not OS.has_feature("web"):
|
||||
OS.delay_msec(500)
|
||||
else:
|
||||
yield(Engine.get_main_loop(), "idle_frame")
|
||||
await get_tree().process_frame
|
||||
|
||||
assert(http.get_status() == HTTPClient.STATUS_CONNECTED) # Check if the connection was made successfully.
|
||||
|
||||
@@ -71,12 +68,7 @@ It will connect and fetch a website.
|
||||
# Keep polling for as long as the request is being processed.
|
||||
http.poll()
|
||||
print("Requesting...")
|
||||
if OS.has_feature("web"):
|
||||
# Synchronous HTTP requests are not supported on the web,
|
||||
# so wait for the next main loop iteration.
|
||||
yield(Engine.get_main_loop(), "idle_frame")
|
||||
else:
|
||||
OS.delay_msec(500)
|
||||
await get_tree().process_frame
|
||||
|
||||
assert(http.get_status() == HTTPClient.STATUS_BODY or http.get_status() == HTTPClient.STATUS_CONNECTED) # Make sure request finished well.
|
||||
|
||||
@@ -109,11 +101,7 @@ It will connect and fetch a website.
|
||||
# Get a chunk.
|
||||
var chunk = http.read_response_body_chunk()
|
||||
if chunk.size() == 0:
|
||||
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")
|
||||
await get_tree().process_frame
|
||||
else:
|
||||
rb = rb + chunk # Append to read buffer.
|
||||
# Done!
|
||||
|
||||
Reference in New Issue
Block a user