Module deferred_batch.lua
deferred_batch Creates a batch-style deferred handler for multiple asynchronous tasks.
Provides per-task and all-tasks completion callbacks with result tracking.
Usage
local batch = deferred_batch()
-- Add async tasks
batch.add(function(done)
-- simulate async work
done("result 1")
end)
batch.add(function(done)
done("result 2")
end)
-- Per-task callback
batch.on_item_done(function(value, index)
print("Task", index, "finished with", value)
end)
-- All-tasks callback
batch.on_all_done(function(results)
print("All tasks completed. Results:", table.concat(results, ", "))
end)
Functions
-
# returns... () -
Returns
-
deferredBatch
A deferred batch table.
deferredBatch
-
# deferredBatch -
Fields
- add function Adds new asynchronous task.
- on_item_done
function
Registers a callback
cb(value, index)that is invoked each time a task completes successfully.indexcorresponds to the order in which tasks were added. - on_all_done
function
Registers a callback
cb(results)that is invoked once after all tasks have completed. If the batch is already finished, the callback is invoked immediately. - is_done boolean Indicates whether all tasks have completed. True only after all tasks have finished.