{"id":"maximumadhd/parallel-worker","name":"parallel-worker","scope":"maximumadhd","platform":"roblox","description":"Parallel task distribution library that abstracts Roblox's actor model away in favor of task modules.","version":"1.0.0","latest":"1.0.0","versions":["1.0.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"35f68f51d642bf18b158156ba0c8c0fc8a3bb63afda45415edf3bcd332ae89d4","likes":0,"downloads":0,"install":"forest install maximumadhd/parallel-worker","url":"https://forest.dev/p/roblox/maximumadhd/parallel-worker","files":"https://api.forest.dev/ai/package/roblox/maximumadhd/parallel-worker/files","readme":"# Roblox-Parallel-Worker\r\n\r\nA ModuleScript library designed to abstract away Roblox's Actor model for parallel execution in favor of a simple task distribution module which handles the lifetime execution of a parallel task!\r\n\r\n## Usage\r\n\r\nTaskModules are ModuleScripts that return a table optionally containing any of the following functions:\r\n\r\n- `TaskModule:Execute(...: any)`\r\n- `TaskModule:Update(deltaTime: number)`\r\n- `TaskModule:IsFinished() -> boolean`\r\n- `TaskModule:GetResults() -> ...any`\r\n\r\nWhen a task is dispatched, each function declared in a module will be called as such:\r\n\r\n|  Function  |     When does it get called?    | In Parallel? |\r\n|------------|---------------------------------|--------------|\r\n| Execute    | Once when a task is dispatched. |      Yes     |\r\n| Update     | On each RunService Heartbeat.   |      Yes     |\r\n| IsFinished | Before/After Update() calls.    |      Yes     |\r\n| GetResults | When a task is finishing.       |      No      |\r\n\r\nThe `Execute` function can be used for a single task to be performed in the dispatched task, or to initialize data for the task instance to use. The `self` variable in your TaskModule's functions will refer to the unique task execution instance, so you can store any lifetime variables of the task in that table. Arguments passed into the ParallelWorker's `Dispatch` and `Invoke` methods are passed in as parameters.\r\n\r\nThe `Update` function can be used for a parallel routine that loops on the RunService's Heartbeat. In the body of `Update`, you can cancel execution of the task via `self:Finish()`.\r\n\r\nThe `IsFinished` function is called when an `Update` function is defined and can be used to statefully terminate execution of the update task loop, instead of calling `self:Finish()`.\r\n\r\nThe `GetResults` function is called upon the task marking itself as complete. This is called even if there's only an `Execute` routine that completes. It can be used to return data back if the task was dispatched through `ParallelWorker:Invoke(...)`.\r\n\r\n## API\r\n\r\n`ParallelWorker.new(taskModule: ModuleScript, allocate: number?) -> ParallelWorker`<br/>\r\nCreates a new ParallelWorker that dispatches parallel tasks of the provided ModuleScript.<br/>\r\nThe optional `allocate` parameter lets you pre-allocate a set number of actors for tasks to use.\r\n\r\n`ParallelWorker:Dispatch(...any) -> Dispatch`<br/>\r\nDispatches a new parallel task of the worker's task module and returns a Dispatch object representing the execution of the task. The task can be cancelled outside of a parallel context by calling `Dispatch:Cancel()`.\r\n\r\n`ParallelWorker:Invoke(...any) -> (boolean, ...any) [Yields]`<br/>\r\nDispatches a new parallel task of the worker's task module and yields the calling thread until execution is completed. Returns true if the task was finished successfully, as well as any data that was received from the task module's GetResults function (if one was defined).\r\n\r\n`Dispatch:Cancel() -> boolean`<br/>\r\nCancels the parallel task associated with this dispatch. Returns true if the cancellation was performed, or false if the task was finished/cancelled already.\r\n","readmeTruncated":false}