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/wait-for

v0.1.5

Published

Wait for instances to exist

Downloads

41

Readme

WaitFor

A simple and safe wait to await the existence of instances.

Roblox's instance tree is ever-changing during runtime due to replication, streaming, and other script-driven changes. As such, it is good to have a safe mechanism to grab either individual or batch instances.

waitForChild

waitForChild<T extends Instance = Instance>(
	parent: Instance,
	childName: string,
	recursive = false,
	timeout = 60,
): Promise<T>

Waits for the childName child to exist within parent. Optionally, a recursive flag can be set to search for the child within all descendants of parent.

If the parent is destroyed, the promise will be rejected with the error WaitForError.Destroyed.

waitForChild(someParent, "SomeChild").then((child) => {
	print(child.GetFullName());
});

waitForChildWhichIsA

waitForChildWhichIsA<T extends keyof Instances>(
	parent: Instance,
	className: T,
	recursive = false,
	timeout = 60,
): Promise<Instance>

Waits for the superclass className to exist within the parent.

waitForChildWhichIsA(someParent, "BasePart").then((part) => {
	print(part.GetFullName());
});

waitForChildOfClass

waitForChildOfClass<T extends keyof Instances>(
	parent: Instance,
	className: T,
	timeout = 60,
): Promise<Instance>

Waits for the given class className to exist within the parent.

waitForChildOfClass(someParent, "PointLight").then((light) => {
	print(light.GetFullName());
});

waitForChildren

waitForChildren(
	parent: Instance,
	childrenNames: string[],
	recursive = false,
	timeout = 60,
): Promise<Instance[]>

Waits for all children childrenNames within parent. Once all children are found, a secondary check is done to make sure none of them were destroyed during the waiting process.

The resolved promise contains an array of children in the same order that they were listed in the childrenNames array.

waitForChildren(vehicle, ["LeftWheel", "RightWheel"]).then((children) => {
	const leftWheel = children[0];
	const rightWheel = children[1];
});

waitForPrimaryPart

waitForPrimaryPart(
	model: Model,
	timeout = 60,
): Promise<BasePart>

Wait for the PrimaryPart of model to exist.

waitForPrimaryPart(someModel).then((primaryPart) => {
	print(primaryPart.GetFullName());
});

waitForObjectValue

waitForObjectValue<T extends Instance = Instance>(
	objectValue: ObjectValue,
	timeout = 60,
): Promise<Instance>

Waits for the value of an ObjectValue to not be nil/undefined.

waitForObjectValue(objectValue).then((value) => {
	print(value);
});

waitForAttribute

waitForAttribute<T>(
	instance: Instance,
	attributeName: string,
	timeout = DEFAULT_TIMEOUT,
): Promise<T>

Waits fot the given attribute to exist.

waitForAttribute<string>(someInstance, "MyString").then((myStr) => {
	print("MyString", myStr);
});

waitForCustom

waitForCustom<T>(
	predicate: () => T | undefined,
	timeout = 60,
): Promise<T>

Waits for the given predicate function to return a non-undefined value.

The predicate function is called every RunService.Heartbeat. As long as the predicate function returns undefined, it will continue to be called every Heartbeat. Once the predicate returns a non-undefined value of type T, the predicate will stop being called and will resolve the promise with the given value.

This can be used for more complex waiting strategies.

waitForCustom(() => {
	const me = Players.FindFirstChild("MyUsername") as Player | undefined;
	return me;
}).then((me) => {
	print(me);
});