Skip to content

Commit

Permalink
Fix an issue with :GetTable and yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampfkarren committed Sep 16, 2019
1 parent 9ee1c43 commit 4bba336
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions DataStore2/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,26 @@ function DataStore:GetTableAsync(default, ...)
assert(default ~= nil, "You must provide a default value.")

return self:GetAsync(default, ...):andThen(function(result)
local changed = false
assert(
typeof(result) == "table",
":GetTable/:GetTableAsync was used when the value in the data store isn't a table."
)

for defaultKey, defaultValue in pairs(default) do
if result[defaultKey] == nil then
result[defaultKey] = defaultValue
changed = true
return Promise.async(function(resolve)
local changed = false
assert(
typeof(result) == "table",
":GetTable/:GetTableAsync was used when the value in the data store isn't a table."
)

for defaultKey, defaultValue in pairs(default) do
if result[defaultKey] == nil then
result[defaultKey] = defaultValue
changed = true
end
end
end

if changed then
self:Set(result)
end
if changed then
self:Set(result)
end

return result
resolve(result)
end)
end)
end

Expand Down

0 comments on commit 4bba336

Please sign in to comment.