Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Use HearbeatSpawn instead of spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Dec 29, 2019
1 parent b355104 commit 9f63684
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/ServerStorage/Aero/Modules/Data/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ local function Log(...)
end


local function HeartbeatSpawn(callback, ...)
local hb
local args = {...}
hb = game:GetService("RunService").Heartbeat:Connect(function()
hb:Disconnect()
callback(unpack(args))
end)
end


-- Check if key matches DataStore criteria:
local function CheckKey(key)
return (type(key) == "string" and #key <= KEY_MAX_LEN)
Expand Down Expand Up @@ -690,7 +700,7 @@ function Data:Start()
local bindable = Instance.new("BindableEvent")
local numCompleted = 0
for _,func in pairs(self._onCloseHandlers) do
spawn(function()
HeartbeatSpawn(function()
local success, err = pcall(func)
if (not success) then
warn("Data BindToClose function failed: " .. tostring(err))
Expand Down Expand Up @@ -751,7 +761,7 @@ function Data:Start()
end)

-- Auto-save cycle:
spawn(function()
HeartbeatSpawn(function()
while (true) do
wait(self.AutoSaveInterval)
if (gameClosing) then break end
Expand Down

0 comments on commit 9f63684

Please sign in to comment.