Is this the correct way to use promise?

Hello everyone !

I have recently discovered Promise by @evaera. I feel like those are super useful but I still don’t really get if i’m using them correctly.

Could you tell me if it is correct ? Or if something should be changed ?

local Players = game.Players
local Promise = require(mypathtopromise)

local GetID = Promise.promisify(function(PlrName)
    print(PlrName)
    if Players:FindFirstChild(PlrName) then
        return Players[PlrName].UserId
    else
       return Players:GetUserIdFromNameAsync(PlrName)
    end
end)

local GetData = Promise.promisify(function(key)
        print(key)
        key = "player_"..key
        return DataStore.PlayersList:GetAsync(key)
    end)
end

function DataStore:GetDataFromPlrName(PlrName)

    return GetID(PlrName):andThen(GetData)
    
end
1 Like