{"id":"bajsucks/paralib","name":"paralib","scope":"bajsucks","platform":"roblox","description":"Simplest parallelization library.","version":"0.1.0","latest":"0.1.0","versions":["0.1.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"alexanderlindholt/signalplus":{"version":">=0.0.0","alias":"signalplus"}},"integrity":"23362e479aa21b527396bb69b00ec15b6d45e18d323babcda5d98e499a020769","likes":0,"downloads":0,"install":"forest install bajsucks/paralib","url":"https://forest.dev/p/roblox/bajsucks/paralib","files":"https://api.forest.dev/ai/package/roblox/bajsucks/paralib/files","readme":"# paralib\nSimplest parallelization library.\n\n## Installation\nadd `paralib = bajsucks/paralib@*` to your wally.toml to install\n\n## Usage\n`paralib.new(n, Module)` - Create a pool of `n` actors with the module as content\n\n`Pool:Invoke(n, FnStr, ...)` - Run `n` jobs of the function `Module[FnStr]`. Yields until the jobs finish and returns their results as a normal table.\n\n`Pool:Fire(n, FnStr, ...)` - Run `n` jobs of the function `Module[FnStr]` without yielding. All results are discarded.\n\n`Pool:Destroy()` - Locks the pool, waits for all jobs to finish and kills it.\n\n## Parallel function Module[FnStr]\n`(iStart, iEnd, Results, ...) -> ()`\n\nwhere\n\n`iStart, iEnd` - job range.\n\n`Results` - SharedTable that will be sent to the caller after all jobs finish. Note that the caller will receive a converted normal table `{}`, not a `SharedTable`.\n\n`...` - Any custom arguments. Note that they must be serializable.\n\n\n## Example usage\n\n```luau\n-- Worker module\nlocal Worker = {}\n\nfunction Worker.SumSquares(iStart, iEnd, Results, values)\n\tfor i = iStart, iEnd do\n\t\tlocal value = values[i]\n\t\tResults[i] = value * value\n\tend\nend\n\nreturn Worker\n```\n\n```luau\n-- Module where you want to call the worker\nlocal Paralib = require(game.ReplicatedStorage.Paralib)\nlocal WorkerModule = script.Parent.WorkerModule -- path to the worker module\n\nlocal pool = Paralib.new(4, WorkerModule)\nlocal values = { 1, 2, 3, 4, 5, 6, 7, 8 }\n\nlocal results = pool:Invoke(#values, \"SumSquares\", values)\n\nfor i, value in results do\n\tprint(i, value)\nend\n\npool:Destroy()\n```\n\nThis creates a pool of 4 actors, runs `WorkerModule.SumSquares` for each item in the array, and returns the results as a normal Luau table.\n\nIf you do not need the result, you can fire-and-forget work:\n\n```luau\nlocal pool = Paralib.new(2, script.Parent.WorkerModule)\npool:Fire(100, \"SumSquares\", values)\npool:Destroy()\n```\n","readmeTruncated":false}