npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rbxts/parallelworker

v0.0.1-ts.1

Published

A 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!

Downloads

6

Readme

Roblox-Parallel-Worker

A 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!

Usage

TaskModules are ModuleScripts that return a table optionally containing any of the following functions:

  • TaskModule:Execute(...: any)
  • TaskModule:Update(deltaTime: number)
  • TaskModule:IsFinished() -> boolean
  • TaskModule:GetResults() -> ...any

When a task is dispatched, each function declared in a module will be called as such in a dispatched task:

| Function | When does it get called? | In Parallel? | |------------|---------------------------------|--------------| | Execute | Once when a task is dispatched. | Yes | | Update | On each RunService Heartbeat. | Yes | | IsFinished | Before/After Update() calls. | Yes | | GetResults | When a task is finishing. | No |

The 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.

The 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().

The 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().

The 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(...).

API

ParallelWorker.new(taskModule: ModuleScript, allocate: number?) -> ParallelWorker Creates a new ParallelWorker that dispatches parallel tasks of the provided ModuleScript. The optional allocate parameter lets you pre-allocate a set number of actors for tasks to use.

ParallelWorker:Dispatch(...any) -> Dispatch Dispatches 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().

ParallelWorker:Invoke(...any) -> (boolean, ...any) [Yields] Dispatches 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).

Dispatch:Cancel() -> boolean Cancels the parallel task associated with this dispatch. Returns true if the cancellation was performed, or false if the task was finished/cancelled already.