This helps tremendously. The only thing that’s still a bit fuzzy for me is the concept of the anonymous function used here:
I understand that
p:next(function(plyData)
implies that this is an anonymous function that will run on resolution of the promise taking plyData as an argument → Then running
CFX_CORE.player_data = plyData
to update CFX_CORE.player_data with said argument. (And vice versa with the anonymous function handling err)
I guess the only thing that’s confusing to me is how those arguments (both plyData and err get populated).
Are they populated when the function
init_has_player_loaded()
gets run with at least ONE argument? I saw a similar example within the Zserge promises doc where a (seemingly arbitrary) argument gets pulled out of thin air called
results
Here’s the code (and my explanation so you know I’m actually doing work to try to understand it!)
deferred.all({
--This argument is a single table containing 3-get-requests to some
-- site to pull some data; The "Deferred all" means that ALL of
-- the actions within this table must be completed in order to be
-- considered "resolved!"
http.get('http://example.com/first'),
http.get('http://example.com/second'),
http.get('http://example.com/third'),
}):next(function(results)
-- This is where the confusion happens - Is results a return from get?
-- What's supposed to go into the arguments section of the
-- "resolution" function?
end, function(results)
-- Same here - They don't do a good job of establishing context
-- which is where my confusion comes from in terms of how the
-- anonymous functions are supposed to be used...
end)