Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nevware21/ts-async

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nevware21/ts-async

support for asynchronous development with a Promise based task Scheduler, several different Promise implementations (synchronous, idle, asynchronous and native runtime wrappers), await helpers, and aliases all built and tested using TypeScript.

  • 0.5.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
311K
decreased by-0.14%
Maintainers
0
Weekly downloads
 
Created

What is @nevware21/ts-async?

@nevware21/ts-async is a TypeScript library that provides utilities for working with asynchronous operations. It includes features such as deferred promises, cancellation tokens, and utilities for working with async iterables.

What are @nevware21/ts-async's main functionalities?

Deferred Promises

Deferred promises allow you to create a promise and resolve or reject it at a later time. This is useful for scenarios where you need to control the timing of the promise resolution.

const { createDeferred } = require('@nevware21/ts-async');

const deferred = createDeferred();

setTimeout(() => {
  deferred.resolve('Hello, World!');
}, 1000);

deferred.promise.then((message) => {
  console.log(message); // Outputs: Hello, World!
});

Cancellation Tokens

Cancellation tokens provide a way to cancel asynchronous operations. This is useful for scenarios where you need to abort an operation based on certain conditions.

const { createCancellationTokenSource } = require('@nevware21/ts-async');

const cts = createCancellationTokenSource();

async function fetchData(token) {
  for (let i = 0; i < 5; i++) {
    if (token.isCancellationRequested) {
      console.log('Operation cancelled');
      return;
    }
    console.log('Fetching data...');
    await new Promise((resolve) => setTimeout(resolve, 1000));
  }
  console.log('Data fetched');
}

fetchData(cts.token);

setTimeout(() => {
  cts.cancel();
}, 2500);

Async Iterables

Async iterables allow you to work with asynchronous sequences of data. This is useful for scenarios where you need to process data that is received over time.

const { createAsyncIterable } = require('@nevware21/ts-async');

async function* asyncGenerator() {
  for (let i = 0; i < 5; i++) {
    await new Promise((resolve) => setTimeout(resolve, 1000));
    yield i;
  }
}

const asyncIterable = createAsyncIterable(asyncGenerator);

(async () => {
  for await (const value of asyncIterable) {
    console.log(value); // Outputs: 0, 1, 2, 3, 4 (one per second)
  }
})();

Other packages similar to @nevware21/ts-async

Keywords

FAQs

Package last updated on 28 Oct 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc