Skip to content

Commit

Permalink
Revert "Merge pull request #44 from fechan/concurrency-fix"
Browse files Browse the repository at this point in the history
This reverts commit 931e69b, reversing
changes made to 9b1aa9a.
  • Loading branch information
fechan committed Nov 18, 2024
1 parent 931e69b commit c594e1e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
2 changes: 0 additions & 2 deletions computercraft/sigils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local Pipe = require('sigils.pipe')
local WebSocket = require('sigils.websocket')
local Utils = require('sigils.utils')
local Logging = require('sigils.logging')
local Concurrent = require('sigils.concurrent')

local DEFAULT_SERVER_URL = 'wss://sigils.fredchan.org'

Expand Down Expand Up @@ -82,7 +81,6 @@ local function init ()
function () WebSocket.doWebSocket(wsContext) end,
function () Controller.listenForCcpipesEvents(wsContext, factory) end,
function () Pipe.processAllPipesForever(factory) end,
function () Concurrent.default_runner.run_forever() end,
function () waitForQuitKey(wsContext) end,
function () while true do os.sleep(0.05) end end -- forces the OS not to lock up
)
Expand Down
9 changes: 3 additions & 6 deletions computercraft/sigils/ItemDetailAndLimitCache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function ItemDetailAndLimitCache.new (missingPeriphs, initialMap)
---@param groups Group[] List of groups to fulfill item limits and details for
function o:Fulfill(groups)
local runner = Concurrent.default_runner
local parallelTasks = {}

for _, group in pairs(groups) do
for _, slot in pairs(group.slots) do
Expand All @@ -42,8 +41,7 @@ function ItemDetailAndLimitCache.new (missingPeriphs, initialMap)
end

-- fulfill itemDetail
table.insert(
parallelTasks,
runner.spawn(
function ()
local periph = peripheral.wrap(slot.periphId)
if periph and o.map[slotId].itemDetail == nil then
Expand All @@ -54,8 +52,7 @@ function ItemDetailAndLimitCache.new (missingPeriphs, initialMap)
)

-- fulfill itemLimit
table.insert(
parallelTasks,
runner.spawn(
function ()
local periph = peripheral.wrap(slot.periphId)
if periph and o.map[slotId].itemLimit == nil then
Expand All @@ -68,7 +65,7 @@ function ItemDetailAndLimitCache.new (missingPeriphs, initialMap)
end
end

runner.await_batch_tasks(parallelTasks)
runner.run_until_done()
end

---Get the item limit of the given Slot
Expand Down
17 changes: 0 additions & 17 deletions computercraft/sigils/concurrent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,13 @@ local function create_runner(max_size)
end
end

---Run an array of functions in parallel and wait for all of them to finish
---@param fns function[] List of functions to wait for the completion of
function await_batch_tasks(fns)
local awaits = {}
for _, task in pairs(fns) do
local resolve, await = create_future()
table.insert(awaits, await)
spawn(function ()
task()
resolve()
end)
end

parallel.waitForAll(table.unpack(awaits))
end

--- A coroutine executor.
-- @type Runner
return {
spawn = spawn,
has_work = has_work,
run_until_done = run_until_done,
run_forever = run_forever,
await_all_tasks = await_all_tasks,
}
end

Expand Down

0 comments on commit c594e1e

Please sign in to comment.