Implement safe item transactions
This commit is contained in:
parent
a8d0888284
commit
5fe73663b9
@ -245,11 +245,14 @@ local PAGES = {
|
|||||||
end,
|
end,
|
||||||
function()
|
function()
|
||||||
print("Importing...")
|
print("Importing...")
|
||||||
|
-- Safely handle transfers, priming computer for a full reset/rescan in case server stops mid-transaction
|
||||||
|
state:itemTransaction(function()
|
||||||
for _,nodeStack in state.node:find(function(s) return not s:isEmpty() end) do
|
for _,nodeStack in state.node:find(function(s) return not s:isEmpty() end) do
|
||||||
if not state.controller:insertStack(nodeStack) then
|
if not state.controller:insertStack(nodeStack) then
|
||||||
print("Couldn't find a free slot for: "..(nodeStack:getDisplayName() or nodeStack:getName() or "[EMPTY]"))
|
print("Couldn't find a free slot for: "..(nodeStack:getDisplayName() or nodeStack:getName() or "[EMPTY]"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
state.pageState[state.currentPage] = pageState
|
state.pageState[state.currentPage] = pageState
|
||||||
@ -284,9 +287,18 @@ local CONTROLLER_STATE = {
|
|||||||
monitor = monitor,
|
monitor = monitor,
|
||||||
nextPage = "MAIN",
|
nextPage = "MAIN",
|
||||||
exit = false,
|
exit = false,
|
||||||
pageState = {}
|
pageState = {},
|
||||||
|
lock = lock,
|
||||||
|
unlock = unlock,
|
||||||
|
isLocked = isLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CONTROLLER_STATE:itemTransaction(transact)
|
||||||
|
self.lock()
|
||||||
|
transact()
|
||||||
|
self.unlock()
|
||||||
|
end
|
||||||
|
|
||||||
os.queueEvent("dummy_event")
|
os.queueEvent("dummy_event")
|
||||||
while not CONTROLLER_STATE.exit do
|
while not CONTROLLER_STATE.exit do
|
||||||
updatePageRender(CONTROLLER_STATE, PAGES)
|
updatePageRender(CONTROLLER_STATE, PAGES)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user