[LOOKING FOR MAINTAINER] Threader - Promise based Actor wrapper

Looking for a maintainer who will keep Threader up-to-date with Roblox’s new updates and perhaps add new features to it. Requirements are:

  • Must be active
  • Must be familiar with how to work with Actors and with Promises
  • Must have a GitHub account
  • Must have experience with LuaU
  • (Optional) Being able to work with Docusaurus to maintain the documentation site

If you are interested then please send me a message so we can talk about the details!

Promise based Actor wrapper.

Version: 1.0.1

Threader is Easy to Use, Promise Based and uses Send Data Get Data structure.
Threader was made to make working with Actors easier and overall tie everything together.
Once Threader had dispatched the work and all the threads had finished, it will return all of the
data that the threads had returned.

Documentation | Github | Installation

Examples:
Terrain generation

Showcase

Creating a Threader Class

Creating a Threader class is very simple. The first argument is always
how many threads are there initially and the last one is the ThreadWorker itself.

local Threader = require(game:GetService("ReplicatedStorage").Threader)

local myThreader = Threader.new(5, PATH.TO.WORKER.MODULE)

Creating a ThreadWorker

A ThreadWorker is a ModuleScript that is used to process the data in all of the threads
once Threader:Dispatch() was called.

local myThreadWorker = Threader.ThreadWorker.new()

function myThreadWorker:OnDispatch(data)
    return data
end

function myThreadWorker:OnCancel()
    print("Cancelled!")
end

return myThreadWorker

Get the Data Back

Getting the data back from all of the threads is very simple! Since Threader is Promise
based after calling Threader:Dispatch() a Promise will be returned that will resolve
once all of the threads had completed or gets rejected if any error occurs!

Main script

local myThreader = Threader.new(5, script.MyThreadWorkerModule)

myThreader:Dispatch(table.create(1000, 1)):andThen(function(results)
    print(results)
end)

ThreadWorker

local MyThreadWorker = Threader.ThreadWorker.new()

function MyThreadWorker:OnDispatch(data)
    local sum = 0

    for _, num in data do
        sum += num
    end

    return sum
end

return MyThreadWorker
40 Likes

I’ve tried playing around with the concept of workers, but this is definitely the best approach i’ve seen so far, great job man!

2 Likes

This is a pretty awesome resource! I’ve been needing to utilize actors more for some stuff I want to do in The Wild West , and this saves me a bit of time

2 Likes

Thank you very much! Please let me know later down the line if you would like to see some changes made to Threader that I might have missed when developing it!

1 Like

Thank you! When I wanted to play around with actors as well I noticed that most of the libraries that were made already required some kinds of preparations to use such as pre-making the actors. This was the main reason that Threader was created to focus on the main part: programming. The rest is taken care by Threader. No need to create actors or set-up boilerplate code so that you can retrieve all your precious data! I hope you will find a good use for it. Happy coding : )

2 Likes

Is this currently working?
Been trying it, used your exact repo, nothing is working.
Have not really tried actors or parallel lua, so is there something I need to enable for this to work?

Hi! Could you send the error message you’re seeing and your project structure?

There’s no errors, It just appears to not be running in parallel, none of the parallel scripts are running inside PlayerScripts or anything.

The project structure is your own which I’ve just cloned and connected to Roblox. Is this Tool (Threader) working for you?

That’s interesting. I’m guessing everything was synced into the right place with rojo. By that I mean Threader is in ReplicatedStorage, the test/Server is in ServerScriptService and test/Client is in PlayerScripts.

Could you perhaps take a picture of your explorer and all the files that belong to Threader are expanded? I have a guess but I’m unsure with the lack of information I have about this problem.

If Threader’s .project.json is used then it should work fine. However if the project was cloned and not Threader’s .project.json is used then there are more steps needed to make it work. This is how it should look like:

This .project.json assumes that Threader was places under a folder called vendors!

"ReplicatedStorage": {
      "Threader": {
        "$path": "vendors/Threader/lib",
        "Promise": {
          "$path": "vendors/Threader/vendors/Promise/lib"
        }
      }
    },

    "ServerScriptService": {
      "ThreaderServer": {
        "$path": "vendors/Threader/test/Server"
      }
    },

    "StarterPlayer": {
      "StarterPlayerScripts": {
        "ThreaderClient": {
          "$path": "vendors/Threader/test/Client"
        }
      }
    }

The last two (“ThreaderServer” and “ThreaderClient”) is only synced in for this example but it should be removed in a production build!

Hope this helps!

The setup to this is extremely tedious. I’m cloning the repo, but theres like 2 folders I need to extract, move to other folders??

Perhaps you should just link the Roblox place + have a Roblox model.

Here’s my Roblox explorer: No errors in terms of requiring wrong paths or anything, just absolutely 0 output and nothing is happening

1 Like

I’m sorry if you find the installation tedious. I’m currently working on getting the library up and running on wally and getting it on the roblox marketplace. For tomorrow/today these installation methods will be available.

For the problem I tried recreating it multiple times directly downloading the source and then using git to clone evaera’s Promise library into vendors/Promise. I even tried the installation method listen on Threader’s website to double check. In both cases I ran into no problems.

I can only think that rojo might be the problem here since I used version 7.4.0-rc3. But again I highly doubt it since it seems that all the scripts did get their RunContext property set correctly.

I’m very sorry that I could not figure out the problem, however here’s the compiled version that includes everything: Threader Dev.rbxl (37.6 KB).

1 Like

You’re good bro! It’s all the process of releasing tools for the public! This file you provided seems to work, how weird that my exact same setup is not working. Starting to think perhaps there’s some sort of property I need to enable for it to function properly (my layout is the exact same as the file you provided).

Or perhaps an outdated Promise I’ve imported? Nonetheless, cool contribution, going to use this for some dope projects!

1 Like

Thank you very much for your kind words! I really appreciate the feedback. I would be very interested as of what caused your issue! Possibly I could even point it out on the documentation.

1 Like

Done some quick testing. Something I’ve completely missed was when I cloned the repo > started up a rojo server > connected to it in Studio. The ThreadHandlerServer and ThreadHandlerClient had their RunContext properties set to Legacy. I do believe this is the issue, is this because I have an outdated version of Rojo that do not support the RunContext in the meta.json files, or is it just not supported at all?

Connected from Rojo using your GitHub repo:
image
Properties:
image

1 Like

I’m pretty sure Rojo started supporting the RunContext property from versions 7.3.0 and beyond. The main reason why RunContext was used instead of making a local script and a script is to move the threads out of the way and protect server sided modules from the clients.

When developing it I used to just parent everything under the module but realized this would not be a good approach since now everyone would have access to the server sided modules placed under ReplicatedStorage. As far as I know exploiters can decompile and view the source code of the modules even when not required.

Thank you for responding back and I will be sure to highlight it on the documentation that an up-to-date version of rojo is required!

1 Like

Ah. Strange. I do have the latest versions of Rojo. Possibly just a Rojo bug?
Edit: I was using Rojo 7.2.1 (7.3.0 is a much required version!)

Fair enough, I’m glad we could find the problem!

1 Like

Finalized release of Threader:

New installation methods:

  • Added Wally installation (ignore v0.1.0)
  • Added Roblox Marketplace installation

Documentation changes:

  • Added a search bar
  • Added results of the Terrain Generation
  • Added link to video that Terrain Generation was based on
  • Added notice of required Promise version
  • Added notice of requireed Rojo version
  • Changed present installation methods to support Wally structure
  • Changed explanation of each variable in Terrain Generation
  • Changed Send Data Get Data pro

Closing thoughts

These will probably be the last changes made to Threader unless some bugs need to be fixed or a feature gets requested that is useful.

Threader is already at a very good stage where it can be used in production without any known bugs. Most of the inner workings of Threader were optimized to my best abilities and the most crucial methods were implemented.

I think adding more methods would be unreasonable. However if there would be feel free to open an issue and I will look into it.

Happy coding!

2 Likes

New update has been released for Threader, changes include:

Added

  • Documentation in Threader module
  • :OnDispatch() now errors if it is not overriden
  • :OnCancel() now warns if it is not overriden and :Threader:Cancel() was called
  • Added examples in documentation

Fixed

  • ThreadHandler not connecting to Dispatch in time
  • Documentation homepage layout for mobiles

Modification

  • Slight changes in documentation
  • Rewrote header
  • Threader.States is set to read-only now
  • Removed some comments

Download links:

Github | Wally | Installation steps

Updated wally package and Github release! Please update to the newer release as it fixes ThreadHandler’s not connecting to the topics in time resulting in them missing the :Dispatch request by Threader!

1 Like

Looking for a maintainer who will keep Threader up-to-date with Roblox’s new updates and perhaps add new features to it. Requirements are:

  • Must be active
  • Must be familiar with how to work with Actors and with Promises
  • Must have a GitHub account
  • Must have experience with LuaU
  • (Optional) Being able to work with Docusaurus to maintain the documentation site

If you are interested then please send me a message so we can talk about the details!