RbxProxy
Search…
Introduction to Promises
Promises in code are cool:tm:
Promises are cool objects that can handle errors efficiently and asynchronously. We use this on the proxy to handle HTTP requests, because they can be unstable this prevents it from having 15,000 errors in the console.
Credits for promises go to evaera
Example:
1
api.trySomething(true):andThen(function(response)
2
print("that something went right!")
3
end):catch(function(err)
4
print("that something did not go right")
5
end)
6
print("this will print instantly")
Copied!
If it errored, it'd go to the catch function as "err", but if it succeeded then it'll go to the "response" field. This is how most of the API functions in this module work.
If you want to wait for the value to be returned you can add ":await" like this:
1
api.trySomething(true):andThen(function(response)
2
print("that something went right!")
3
end):catch(function(err)
4
print("that something did not go right")
5
end):await()
6
print("this will print after")
Copied!
Is this code too long / complicated for you? We can simplify it even further!
1
-- example code:
2
local success,response = client.group:getGroupInformation(1):await();
Copied!
For a more in-depth explanation than whatever this is, check out this post by evaera. This is the code that is used.
Last modified 1mo ago
Copy link