@rbxts/luau-thread
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Thread

Fork of luau-thread for Roblox-ts

The module must first export a function:

// src/shared/module
export = function(timeToWait: number) {
	task.wait(timeToWait);
	print("waited", timeToWait, "second(s)");
}

Then, to get our module, we can use the new $getModuleTree macro, and the function provided in this library

import Thread from "@rbxts/luau-thread";

const [root, parts] = $getModuleTree("shared/module");
const module = Thread.getModuleByTree(root, parts);

Afterwards, we can spawn the module and wait for it to finish:

const identifier = Thread.spawn(module, 1);
Thread.join(identifier);

// prints: waited 1 second(s)

We can also spawn it multiple times, and wait for all threads to finish:

const identifiers = [];

for (const i of $range(1, 10)) {
	identifiers.push(Thread.spawn(module, i));
}

Thread.join(identifiers);

// prints: waited 1 second(s)
// ...
// prints: waited 10 seconds(s)

Readme

Keywords

none

Package Sidebar

Install

npm i @rbxts/luau-thread

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

8.85 kB

Total Files

7

Last publish

Collaborators

  • returnedtrue