Variable with Promise has two different values in script

Hello. I have a Knit service which has a function to return a table in it, and I access it from a regular ModuleScript using Knit.Start():andThen. I print it after, and it looks normal, but when I print it later in the script, it prints Promise(Resolved). Any way I can fix it?

Try using the :await() method on the Promise object to wait for it to be resolved before accessing its value.

-- later when you print  in the script...
local data = Promise:await()
print("Data is now:", data)

This works! I have one question though, is there really not an easier way to do this? I feel like I’m overscripting just getting a table

local function GetBlocksList()
    repeat task.wait() until Blocks
    local success, t = Blocks.GetList():await()
    return t
end

You could just use instead.

function GetBlocksList()
    return Blocks.GetList():await()
end

This will assume that the Blocks is already available if waiting for Blocks object to become available is important for what you are trying to do then I’d keep it the way you had it just for safe measures.

To my knowledge there isn’t really a simpler way to get the result of an asynchronous operation that returns a Promise object.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.