-
Notifications
You must be signed in to change notification settings - Fork 19
Update PlayFabHttp.gd #165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Improve http_request to not hang awaiting callback
|
Thank you very much for your pull request! However, I did ask you in the other issue to first discuss this. Can you please elaborate a bit more why you want to change like you proposed? Since this is a breaking change, I would like to understand your use-case. Also, this needs documentation updates, and tests would be great as well! Thank you! |
|
hey, first of all everything is super new to me so yeah I am getting lost in my own solutions. I am using Promises lib to wrap any functions that use post_dict. It like allows me to simply await my functions in a convenient way. I am trying to write the explanation as best as I can but no luck, so heres an example of my solution: func UpdateNickname(playerid: String, new_nick: String) -> Promise:
var body = {
"PlayFabId": playerid,
"DisplayName": new_nick
}
print("JSON TEST: ",JSON.stringify(new_nick))
return Promise.new(func(resolve, reject):
PlayFabManager.client.post_dict(
body,
"/Admin/UpdateUserTitleDisplayName",
func(response: Dictionary) -> void:
var result: Dictionary = {}
print(response)
if response.has("errorMessage"):
# PlayFab returned an error (duplicate name, etc.)
result["success"] = false
result["error"] = response["errorMessage"]
print("Nickname change failed: ", response["errorMessage"])
resolve.call(result)
elif response.has("data") and response["data"].has("DisplayName"):
# Success
result["success"] = true
result["displayName"] = response["data"]["DisplayName"]
print("Nickname successfully changed to: ", result["displayName"])
resolve.call(result)
else:
# Unexpected structure
result["success"] = false
result["error"] = "Unexpected response"
result["raw"] = response
print("Unexpected nickname response: ", response)
resolve.call(result)
,
_headers
)
) |
|
You handle similar functions in a controller class, lets say, and then you can conveniently await them anywhere in your code. But if the callback never triggers, it hangs |
|
What is the intended flow of post_dict? |
|
Which Promises lib are you using? I don't really like the unifying of |
|
Using this tiny utility, works great: So how would you go about this? About awaiting post_dict method? |
|
So yea, I wanted a better way of getting to call the right callback, once the request has finished. Ideally, I want users to not set up the same conversion with So a promise system like the one you mentioned might be something to look at. Another way of doing this, would be to uniquely track the requests, with an ID of sorts. The thing is, GDScript is very limited, and I also didn't really have time to look at all the new stuff that was introduced with the 4.x line of GDScript (as you can see, I don't even use |
|
so in essence: I would appreciate a solution that can actually correlate the request to the response and call a user-defined callback, prior to that, actually deserializing to the expected model. If you can look into that, I'd be extremely thankful! |
|
That pretty much means having all available playfab functions defined in classes |
|
well, we won't have all functions and models defined, so we need to find away around that |
|
I'd like to thank you for your work, it helped my project substantially. In my specific case it is preferable to have the callback invoked no matter the response code. I believe it is preferable in general. I expect every http_request to return a response, instead of a redirect through signals in case of an error, it complicates things. My pull request does not neglect the error wrappers, its a good base - it simply passes the callback at all times, which I believe makes sense. |
|
I think you may be right here :) I have a few other priorities, when those are done, I'll look at this again. Truth be told, this whole HTTP class needs to be redone anyways. It's not scalable and with 4.x, specifically 4.5, I have a lot more tools to make it better. Thanks for your contribution! I think I'm going with this or at the very least, build on it! |
Improve http_request to not hang awaiting callback