New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@rbxts/task-queue

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rbxts/task-queue

Queue of cancellable tasks that is shifted and resumed whenever a task finishes

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

TaskQueue

In the example below, we add two tasks to the queue, and the first one yields longer than the main thread does. Because the cancel request is sent before the task.wait(3) in the first task had finished, "b" and "c" will not print.

import TaskQueue from "@rbxts/task-queue";

const queue = new TaskQueue();

queue.AddTask(() => {
    print("a");
    task.wait(3);
    print("b");
    task.wait(1);
});

queue.AddTask(() => {
    print("c");
});

task.wait(2);
queue.Clear();

Events can be registered as dependencies for the queue, so that when one of its events is fired, the queue will cancel all the tasks that contains that event.

import { myEvent } from "./events";

queue.AddTask(() => {
    task.wait(3);
    print("hello there");
}, [myEvent]);

// will prevent the task from printing "hello there"
myEvent.Fire();

Additionally, there is a method exclusive to promises, but the way it works is different from AddTask. Instead of resolving the promise when its thread is consumed by the queue, it'll be cancelled.

const promise = new Promise((resolve) => {
    const status = getPlayerStatus();
    resolve(status);
}).timeout(60);

queue.AddTask(() => { ... });
// ...

queue.AddPromise(promise);

This is essentially a sugar for:

queue.AddTask(() => {
    promise.cancel();
});

FAQs

Package last updated on 09 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts