{"id":"jammees/threader","name":"threader","scope":"jammees","platform":"roblox","description":"Promise based Actor wrapper.","version":"1.0.1","latest":"1.0.1","versions":["0.1.0","1.0.0","1.0.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"evaera/promise":{"version":"^4.0.0","alias":"Promise"}},"integrity":"33499b1084eda8368b318adde8b255e4f4e8bc32f11f2b9d7d89d9c2126146cc","likes":0,"downloads":0,"install":"forest install jammees/threader","url":"https://forest.dev/p/roblox/jammees/threader","files":"https://api.forest.dev/ai/package/roblox/jammees/threader/files","readme":"<div align=\"center\">\r\n    <img height=150 src=\"./docs/static/img/SVG Threader logo dark.svg#gh-light-mode-only\">\r\n    <img height=150 src=\"./docs/static/img/SVG Threader logo light.svg#gh-dark-mode-only\">\r\n    \r\n<h3>Promise based Actor wrapper.</h3>\r\n\r\nVersion: <b>1.0.1</b>\r\n</div>\r\n\r\nThreader is __Easy to Use__, __Promise Based__ and uses __Send Data Get Data__ structure.\r\nThreader was made to make working with Actors easier and overall tie everything together.\r\nOnce Threader had dispatched the work and all the threads had finished, it will return all of the \r\ndata that the threads had returned.\r\n\r\n## Showcase\r\n\r\n### Creating a Threader Class\r\n\r\nCreating a Threader class is very simple. The first argument is always \r\nhow many threads are there initially and the last one is the ThreadWorker itself.\r\n\r\n```lua\r\nlocal Threader = require(game:GetService(\"ReplicatedStorage\").Threader)\r\n\r\nlocal myThreader = Threader.new(5, PATH.TO.WORKER.MODULE)\r\n```\r\n\r\n<br>\r\n\r\n### Creating a ThreadWorker\r\n\r\nA ThreadWorker is a ModuleScript that is used to process the data in all of the threads \r\nonce `Threader:Dispatch()` was called.\r\n\r\n```lua\r\nlocal myThreadWorker = Threader.ThreadWorker.new()\r\n\r\nfunction myThreadWorker:OnDispatch(data)\r\n    return data\r\nend\r\n\r\nfunction myThreadWorker:OnCancel()\r\n    print(\"Cancelled!\")\r\nend\r\n\r\nreturn myThreadWorker\r\n```\r\n\r\n<br>\r\n\r\n### Get the Data Back\r\n\r\nGetting the data back from all of the threads is very simple! Since Threader is Promise \r\nbased after calling Threader:Dispatch() a Promise will be returned that will resolve \r\nonce all of the threads had completed or gets rejected if any error occurs!\r\n\r\n#### Main script\r\n\r\n```lua\r\nlocal myThreader = Threader.new(5, script.MyThreadWorkerModule)\r\n\r\nmyThreader:Dispatch(table.create(1000, 1)):andThen(function(results)\r\n    print(results)\r\nend)\r\n```\r\n\r\n#### ThreadWorker\r\n\r\n```lua\r\nlocal MyThreadWorker = Threader.ThreadWorker.new()\r\n\r\nfunction MyThreadWorker:OnDispatch(data)\r\n    local sum = 0\r\n\r\n    for _, num in data do\r\n        sum += num\r\n    end\r\n\r\n    return sum\r\nend\r\n\r\nreturn MyThreadWorker\r\n```","readmeTruncated":false}