Skip to content

Commit

Permalink
Rollback (properly)
Browse files Browse the repository at this point in the history
i hate git
  • Loading branch information
metatablecat committed Jul 21, 2024
1 parent a16b31e commit 94427ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
21 changes: 12 additions & 9 deletions src/lib/Dispatcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,21 @@ local function free(state, ok, err, o, service)
local held = state.HeldThreads; state.HeldThreads = {}

for _, v in dispatchers do
task.defer(v, ok, err)
task.spawn(v, ok, err)
end

for _, v in held do
task.defer(v, ok, err)
task.spawn(v, ok, err)
end
end

local function timeoutTracker(o, state): thread?
if state.TimeoutDisabled then return end

return task.delay(5, ERROR.DISPATCHER_TIMEOUT, o:GetID(true))
return task.spawn(function(self)
task.wait(5)
ERROR.DISPATCHER_TIMEOUT(self:GetID(true))
end, o)
end

local function serviceStartup(service)
Expand Down Expand Up @@ -91,7 +94,7 @@ local function serviceStartup(service)
serviceState.State = "finished"

for _, t in serviceState.HeldThreads do
task.defer(t)
task.spawn(t)
end
end
end
Expand All @@ -102,6 +105,7 @@ local function runObjectAction(
service,
state
)
state.Spawned = true
state.Thread = coroutine.running()

for _, v in state.AwaitFor do
Expand All @@ -116,7 +120,7 @@ local function runObjectAction(
free(state, ok, err)

if service.Updating and o.Update then
task.defer(doServiceLoopForObject, o, service, state)
task.spawn(doServiceLoopForObject, o, service, state)
end

return ok, err
Expand Down Expand Up @@ -152,8 +156,7 @@ local function spawnObject(object, service, state, asyncMode)
object:HandleAsync(asyncMode)
end

state.Spawned = true
task.defer(runObjectAction, object, spawnSignal, service, state)
task.spawn(runObjectAction, object, spawnSignal, service, state)

if not asyncMode then
return object:Await()
Expand All @@ -169,7 +172,7 @@ function Dispatcher.spawnObject(o, fPrivate, xpcallHandler, asyncHandler)

-- basically new logic for Spawn
if state.Spawned then
ERROR.DISPATCHER_ALREADY_SPAWNED(o:GetID(true))
ERROR:DISPATCHER_ALREADY_SPAWNED(o)
end

if xpcallHandler then
Expand Down Expand Up @@ -203,7 +206,7 @@ end

function Dispatcher.slotHandleAsync(o, asyncHandler)
local state = Dispatcher.getObjectState(o)
if not state then task.defer(asyncHandler, false, "The object was destroyed") end
if not state then task.spawn(asyncHandler, false, "The object was destroyed") end

if state.ErrMsg then
asyncHandler(false, state.ErrMsg)
Expand Down
1 change: 0 additions & 1 deletion src/lib/Error.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ local ErrorBuffer = {

ANALYSIS_MODE_NOT_AVAILABLE = e("ANALYSIS_MODE_NOT_AVAILABLE", "Analysis mode cannot be used in %s", "E"),

DESTROYED_BEFORE_SPAWNED = e("DESTROYED_BEFORE_SPAWNED", "Attempted to destroy object %s before its spawned", "E"),
DISPATCHER_ALREADY_SPAWNED = e("DISPATCHER_ALREADY_SPAWNED", "Object %s has already been spawned.", "E"),
DISPATCHER_DESTROYED_OBJECT = e("DISPATCHER_DESTROYED_OBJECT", "Object %s cannot be spawned because it has been destroyed.", "E"),
DISPATCHER_SPAWN_ERR = e("DISPATCHER_SPAWN_ERR", "An object experienced an error while spawning: %s", "W"),
Expand Down
8 changes: 2 additions & 6 deletions src/lib/Object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,15 @@ return function(params: {[string]: any}, service)
local service = OBJECT_PRIVATE[self].Service
local state = Dispatcher.getObjectState(self)

if not state.Spawned then
ERROR.DESTROYED_BEFORE_SPAWNED(self:GetID(true))
end

if Dispatcher.getObjectState(self) then
Dispatcher.cleanObjectState(self)
OBJECT_PRIVATE[self] = nil

local destroying = self.Destroying
local fragRemoved = service.ObjectRemoved

if destroying then task.defer(destroying, self) end
if fragRemoved then task.defer(fragRemoved, service, self) end
if destroying then task.spawn(destroying, self) end
if fragRemoved then task.spawn(fragRemoved, service, self) end

Dispatcher.stop(self, state)
end
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ local function createObjectForService(params, service)
if not Common.AnalysisMode then
Dispatcher.initObjectState(o)
local objAdded = service.ObjectAdded
if objAdded then task.defer(objAdded, service, o) end
if objAdded then task.spawn(objAdded, service, o) end
end

return o
Expand Down

0 comments on commit 94427ca

Please sign in to comment.